這裏是我的控制器update_attributes方法是行不通的
class ActivitiesController < ApplicationController
def exercises
if current_user.userprofile.present? #chef whether there is a userprofile object
@weeknum = current_user.userprofile.week
@dayly_activity = Activity.where(:week => 1, :day => 'Monday').first
end #end check userprofile
end
def updatexercises
respond_to do | format |
@dayly_activity = Activity.where(:week => 1, :day => 'Monday').first
@dayly_activity.update_attributes(params[:@dayly_activity])
@dayly_activity.save
format.html { render action: "exercises" }
end
end
end
而且我的模板
<h1>WEEKLY EXERCICES</h1>
Day : <%= @dayly_activity.day %>
<%= form_for(@dayly_activity, :url => { :action => "updatexercises" }) do | f | %>
<table>
<tr>
<td>Jogging:</td>
<td>
<% list = (0..20).to_a %>
<%= f.select :jog, list %>
x 0.1 km
</td>
</tr>
<tr>
<td>Bicycling:</td>
<td>
<% list = (0..10).to_a %>
<%= f.select :bicycl, list %>
km
</td>
</tr>
<tr>
<td>Push ups:</td>
<td>
<% list = (0..20).to_a %>
<%= f.select :pushups, list %>
x 10 times
</td>
</tr>
<tr>
<td colspan = "2"><%= f.submit %></td>
</tr>
</table>
<% end %>
當我按一下按鈕,每日+活動對象沒有被保存。我失去了一些東西
編輯
我試圖硬編碼這種方式,並保存到數據庫中。
@dayly_activity.jog = 17
@dayly_activity.pushups = 13
@dayly_activity.save
顯然,這個問題必須與update_attributes方法
'PARAMS [:@ dayly_activity]''刪除'@ – ck3g
這是唯一的問題嗎?我已經刪除了@符號,它仍然沒有保存。 – Richard77