0
我試圖返回一個值回我的看法,雖然沒有多少成功回報率,如果.. else語句
錯誤
未定義的局部變量或#
方法`時間表」模型
def win_lose_tie
if schedule.for.to_i == schedule.against.to_i then
:tie
elsif schedule.for.to_i > schedule.against.to_i ? :win : :lose
end
end
幫手
def win_lose_tie_display(value)
case value
when :win
"W"
when :lose
"L"
when :tie
"T"
else
"unknown win/lose/tie value"
end
end
視圖
<%= win_lose_tie_display(schedule.win_lose_tie) %>
所有這些返回以下錯誤
NameError附表#索引
顯示/用戶/ ** /站點/ rails_projects/** /應用/視圖/日程安排/ index.html.erb其中行46#上升:
43: <% @schedules.each do |schedule| %>
44: <tr>
45: <td><%= schedule.event %></td>
46: <td><strong><%= win_lose_tie_display(schedule.win_lose_tie) %></strong> <%= schedule.for %> — <%= schedule.against %></td>
47: <td><%= schedule.opponent %></td>
48: <td><%= schedule.date.to_formatted_s(:event_date) %>
49: </td>
任何幫助,這將是偉大的
在此先感謝
您需要提供有關該錯誤的更多信息。點擊Application Trace或Full Trace,前幾行應該提供必要的信息。你的'win_lose_tie'看起來很尷尬。嘗試重構它以擁有更多線條或至少更多大括號。 –
application trace在app_views/schedules/index.html.erb:46:in _app_views_schedules_index_html_erb___1705540283_2185334800' app/views/schedules/index.html中返回以下'app/models/schedule.rb:12:''win_lose_tie' .erb:43:在每個' ' 應用/視圖/時間表/ index.html.erb:43:在'_app_views_schedules_index_html_erb___1705540283_2185334800' 應用程序/控制器/ schedules_controller.rb:7:在'索引' –
@ChristophPetschnig我已經重構了代碼,幷包含一些更多信息 –