这是我的控制器
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 %>
当我单击按钮时,Daily+activity 对象没有被保存。我错过了什么吗
编辑
我试图以这种方式进行硬编码并将其保存到数据库中。
@dayly_activity.jog = 17
@dayly_activity.pushups = 13
@dayly_activity.save
显然,问题一定出在update_attributes