gpt4 book ai didi

ruby-on-rails - rails formtastic 嵌套形式警告 : Can't mass-assign protected attributes

转载 作者:行者123 更新时间:2023-12-01 13:10:09 33 4
gpt4 key购买 nike

我有以下模型:

class CapstoneMilestone < ActiveRecord::Base

attr_accessible :capstone_id, :milestone_id, :rank, :id, :status, :statusweight, :rating, :ratingweight
belongs_to :milestone
belongs_to :capstone

accepts_nested_attributes_for :capstone, :allow_destroy => false
accepts_nested_attributes_for :milestone, :allow_destroy => false


end

class Milestone < ActiveRecord::Base

has_many :capstone_milestones
has_many :capstones, :through => :capstone_milestones
attr_accessible :id, :name, :description, :department_id, :project

accepts_nested_attributes_for :capstone_milestones, :allow_destroy => true

end

我也有一个 formtastic 的形式:

<% semantic_form_for(@capstone_milestone) do |form| %>

<%= form.semantic_errors :state %>
<% form.inputs do %>
<%= form.input :capstone_id , :as => :select, :collection => Capstone.all %>
<%= form.input :milestone_id, :as => :select, :collection => Milestone.all %>
<%= form.input :status, :as => :numeric%>
<%= form.input :statusweight, :as => :numeric%>
<%= form.input :rating, :as => :numeric%>
<%= form.input :ratingweight, :as => :numeric%>


<% end %>
<%= form.inputs :name, :for => :milestone%>

<%= form.buttons %>

<% end %>

我的 capstone_milestone Controller (应该)负责更新:

  def update
@milestone=@capstone_milestone.milestone # I also removed these 2 lines without success
@milestone.update_attributes(params[:milestone_id])

respond_to do |format|
if @capstone_milestone.update_attributes(params[:capstone_milestone])
format.html { redirect_to(session[:return_to], :notice => 'Milestone was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @capstone_milestone.errors, :status => :unprocessable_entity }
end
end
end

当我提交表单时,capstone_milestone 已更新,但链接的里程碑未更新。

这是服务器日志:

Started POST "/capstone_milestones/12" for 127.0.0.1 at 2011-03-18 11:40:30 +0100
Processing by CapstoneMilestonesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"ZkErrLTpdp56BASPdZiiT6ZcvUx5KsI+Gm3JLnzM6D0=", "capstone_milestone"=>{"capstone_id"=>"100001", "milestone_id"=>"100002", "status"=>"80.0", "statusweight"=>"1.0", "rating"=>"", "ratingweight"=>"1.0", "milestone_attributes"=>{"name"=>"Land Control Analysis 2", "id"=>"100002"}}, "commit"=>"Update Capstone milestone", "id"=>"12"}
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1
CapstoneMilestone Load (0.4ms) SELECT `capstone_milestones`.* FROM `capstone_milestones` WHERE `capstone_milestones`.`id` = 12 ORDER BY capstone_milestones.rank LIMIT 1
Milestone Load (0.3ms) SELECT `milestones`.* FROM `milestones` WHERE `milestones`.`id` = 100002 LIMIT 1
SQL (0.1ms) BEGIN
SQL (0.1ms) COMMIT
SQL (0.1ms) BEGIN
WARNING: Can't mass-assign protected attributes: milestone_attributes

如有任何想法或建议可以解锁我,我们将不胜感激!

最佳答案

您需要将:milestone_attributes 添加到CapstoneMilestoneattr_accessible

attr_accessible :capstone_id, :milestone_id, :rank, :id, :status, :statusweight,
:rating, :ratingweight, :milestone_attributes

关于ruby-on-rails - rails formtastic 嵌套形式警告 : Can't mass-assign protected attributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5350881/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com