我对编码一般都很陌生。我试图通过创建一个网络应用程序来支持我的技能,该应用程序允许人们对特定菜肴排列他们最喜爱的餐馆(例如汉堡包的顶级餐厅)。菜品中的NoMethodError#new
我目前正在致力于连接表,链接餐厅和菜肴。我正在尝试添加select_tags
以从菜盘和餐厅表中选择一个菜。我得到一个NoMethodError
。希望对我的错误有所了解。谢谢!
错误:
NoMethodError in Dishings#new Showing /Users/frederick7/code/Appdev/pear_review/app/views/dishings/new.html.erb
其中行#27提出:
undefined method `map' for #
提取的源(围绕线#27):
</label>
<%= select_tag(:restaurant_id, options_from_collection_for_select(@dishing, 'id', 'restaurant_id', @dishing.id)) %>
</div>
<!-- Label and input for dish_id -->
以下是在视图/ dishings相关的代码/new.html.erb:
<!-- Label and input for restaurant_id -->
<div class="form-group">
<label for="restaurant_id" class="control-label">
Restaurant
</label>
<%= select_tag(:restaurant_id, options_from_collection_for_select(@dishing, 'id', 'restaurant_id', @dishing.id)) %>
</div>
<!-- Label and input for dish_id -->
<div class="form-group">
<label for="dish_id" class="control-label">
Dish
</label>
<%= select_tag(:dish_id, options_from_collection_for_select(@dishing, 'id', 'dish_id', @dishing.id)) %>
</div>
这可能是相关的代码dishings_controller.rb:
def new
@dishing = Dishing.new
end
def create
@dishing = Dishing.new
@dishing.restaurant_id = params[:restaurant_id]
@dishing.dish_id = params[:dish_id]
if @dishing.save
redirect_to "/dishings", :notice => "Dishing created successfully."
else
render 'new'
end
end
'.map'是一个集合,'options_from_collection_for_select'需要一个集合中,并呼吁'它.map',但'@ dishing'不一个集合 – lusketeer