我正在处理嵌套资源项目,并且在我的步骤控制器中出现错误:
def create
@step = Step.new(step_params)
respond_to do |f|
if @step.save
f.html { redirect_to @step, notice: 'Step was successfully created.' }
f.json { render action: 'show', status: :created, location: @step }
else
f.html { render action: 'new' }
f.json { render json: @step.errors, status: :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
undefined method `step_url' for #<StepsController:0x007feeb6442198>
Run Code Online (Sandbox Code Playgroud)
我的路线看起来像这样:
root 'lists#index'
resources :lists do
resources :steps
end
Run Code Online (Sandbox Code Playgroud) 我的项目模型属于我的订单模型,我的订单模型有很多项目。当我尝试传递以下参数时:
{"utf8"=>"?", "authenticity_token"=>"mPKksp+W5lZc7+lrc90trtCzX+UtPj4PI8boNf7vb+nneMF/J5SSBz8Nmh+CQ//DkmuVP2MJf7gS3oLqpZcM2Q==", "order"=>{"special_instructions"=>"", "item_attributes"=>{"topping_ids"=>["1", "2", "5"]}}, "commit"=>"Save"}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
no implicit conversion of String into Integer
Run Code Online (Sandbox Code Playgroud)
该错误发生在我的Orders控制器中的create操作中:
@order = Order.new(order_params)
Run Code Online (Sandbox Code Playgroud)
这是我的params方法的样子:
def order_params
params.require(:order).permit(:completed, :special_instructions, items_attributes: [ :size, topping_ids: [] ])
end
Run Code Online (Sandbox Code Playgroud)
这是我的订单模型:
class Order < ActiveRecord::Base
belongs_to :user
has_many :items
accepts_nested_attributes_for :items
end
Run Code Online (Sandbox Code Playgroud)
这是我的物品模型:
class Item < ActiveRecord::Base
belongs_to :order
has_many :sizes
has_many :item_toppings
has_many :toppings, through: :item_toppings
has_many :inverse_item_toppings, class_name: 'ItemTopping', foreign_key: 'item_id'
has_many :inverse_toppings, through: :inverse_item_toppings, source: :item
accepts_nested_attributes_for :sizes, reject_if: :all_blank, allow_destroy: true
end
Run Code Online (Sandbox Code Playgroud)
这是我架构的相关部分
create_table …Run Code Online (Sandbox Code Playgroud)