0

Order.rb:

class Order < ActiveRecord::Base
     has_one :review
end

Review.rb:

class Review < ActiveRecord::Base
    belongs_to :order
end

I need to build a review, im using this method:

  class OrdersController < ApplicationController
    def build_review
      @review = Review.new(:order => @order)
    end

but i get this error: Can't mass-assign protected attributes: order

any ideas?

4

2 回答 2

6

You need to white list order for mass assignment via a params hash. Read http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html

Add this to the Review model

attr_accessible :order

于 2013-03-26T04:31:30.890 回答
0

最好使用@review = @order.build_review而不是将其添加到 attr_accessible。以防万一 ;)

于 2013-03-26T06:27:58.417 回答