Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript nil:NilClass rails 4的未定义方法“category”_Javascript_Ruby On Rails_Json_Coffeescript - Fatal编程技术网

Javascript nil:NilClass rails 4的未定义方法“category”

Javascript nil:NilClass rails 4的未定义方法“category”,javascript,ruby-on-rails,json,coffeescript,Javascript,Ruby On Rails,Json,Coffeescript,在视图/报价/索引中: <%= f.collection_select :catId_get, Category.order(:name), :id, :name, { include_blank: true }, {data:{ dynamic_selectable_url: dynamic_select_offers_path(':catId_get'), dynamic_selectable_target: '#offer_menu_id' }} %&g

在视图/报价/索引中:

<%= f.collection_select :catId_get, Category.order(:name), :id, :name, 
  { include_blank: true },
  {data:{
    dynamic_selectable_url: dynamic_select_offers_path(':catId_get'),
    dynamic_selectable_target: '#offer_menu_id'
  }} %>     


<%= f.collection_select :menuName_get, @offer.Category.try(:menus) || [], :id,:menu_item_name, :include_blank => true  %>
在controllers/dynamic_select/offers_controller.rb中:

module DynamicSelect
class OffersController < ApplicationController
  respond_to :json
  def index
    @menus=Menu.where(:category_id=>params[:catId_get])
    respond_with(@menus)
   end
end
end
在db/migrate中:

我是rails新手。当我从其父下拉列表中选择一个类别时,我想填充菜单项下拉列表中的数据。请帮帮我,我已经被困在这两天了

Started GET "/offers/index" for 127.0.0.1 at 2014-10-29 16:25:57 +0530
Processing by OffersController#index as HTML
 ←[1m←[35mCategory Load (15.6ms)←[0m  SELECT `categories`.*
FROM `categories`   ORDER BY `categories`.`name` ASC
  Rendered 
offers/index.html.erb within layouts/application (15.6ms)
Completed 

500 Internal Server Error in 32ms

ActionView::Template::Error 

(undefined method `Category' for nil:NilClass):
    316:                           
     <div>
    317:                                        <%= f.label "Select Menu:" %> 

&nbsp;
    318:
    319:                                        <%= f.collection_select 

:menuName_get, @offer.Category(:menus) || [], :id,:menu_item_name,
:include_blank => true  %>
    320:
    321:
    322:                                

</div>
  app/views/offers/index.html.erb:319:in `block in 

_app_views_offers_index_html_erb___717332836_61645344'


app/views/offers/index.html.erb:303:in 

`_app_views_offers_index_html_erb___717332836_61645344'
您尚未在控制器中设置@offer,例如:

@offer = Offer.first
然后您可以使用:

@offer.categories

Not@offer.Category记下大小写和复数。

这里的@offer是什么?您是否也可以发布它的模型类代码?在models/offer中:有很多:categories@Jack-你能把你的错误信息和回溯一起发布吗,请?请查看我编辑的代码。我已经发布了上面的错误消息。仍然是相同的错误…nil:NilClass的未定义方法“categories”…..@juanpstas请告诉我,我的模型中有什么需要添加的。谢谢,这意味着您的数据库中没有任何报价。你的问题不清楚,因为你没有解释你想要什么,我可以推断出来,但不清楚。
Started GET "/offers/index" for 127.0.0.1 at 2014-10-29 16:25:57 +0530
Processing by OffersController#index as HTML
 ←[1m←[35mCategory Load (15.6ms)←[0m  SELECT `categories`.*
FROM `categories`   ORDER BY `categories`.`name` ASC
  Rendered 
offers/index.html.erb within layouts/application (15.6ms)
Completed 

500 Internal Server Error in 32ms

ActionView::Template::Error 

(undefined method `Category' for nil:NilClass):
    316:                           
     <div>
    317:                                        <%= f.label "Select Menu:" %> 

&nbsp;
    318:
    319:                                        <%= f.collection_select 

:menuName_get, @offer.Category(:menus) || [], :id,:menu_item_name,
:include_blank => true  %>
    320:
    321:
    322:                                

</div>
  app/views/offers/index.html.erb:319:in `block in 

_app_views_offers_index_html_erb___717332836_61645344'


app/views/offers/index.html.erb:303:in 

`_app_views_offers_index_html_erb___717332836_61645344'
@offer = Offer.first
@offer.categories