我有2个型号。任务和位置has_one关系控制器更新导轨3
每个任务HAS_ONE位置
task.rb
has_one :location
我想创建我的位置模型控制器。 这是新形式
<%= form_for(@task.build_Location, :url => task_Location_path(@task)) do |f| %>
Fields
<%= f.submit %>
<% end %>
和编辑表单
<%= form_for(@task.Location, :url => task_Location_path(@task)) do |f| %>
Fields
<%= f.submit %>
<% end %>
目前所有功能与更新除外正常运行。
def create
@location = @task.create_Location(params[:location])
end
def update
@location = @task.locations.find(params[:id])
end
什么是定义此方法的正确方法?
'@ location.update_attributes(PARAMS [:位置])'可以工作 – MrYoshiji