2013-01-14 65 views
0

我有房節中的一些錯誤索引方法請參見錯誤是對指數方法錯誤「爲NilClass未定義的方法`MODEL_NAME」:類」

NoMethodError in Rooms#index 

Showing /home/kingdark/Repos/glowfish/app/views/rooms/_room.html.erb where line #2 raised: 

undefined method `model_name' for NilClass:Class 

Extracted source (around line #2): 

1: <h1>&nbsp;Rooms List <span class='pull-right'> <%= link_to "New Room", new_room_path, class: 'btn btn-primary' %> </span> </h1> 
2: <%= content_tag_for :div , room, class: 'row-fluid' do %> 
3: <div id="r-index_content"> 
4: <li> 
5: <span class='span9' > 

Trace of template inclusion: app/views/rooms/index.html.erb 

Rails.root: /home/kingdark/Repos/glowfish Application Trace | Framework Trace | Full Trace 

app/views/rooms/_room.html.erb:2:in `_app_views_rooms__room_html_erb__3875627950727331108_69928712927400' app/views/rooms/index.html.erb:1:in `_app_views_rooms_index_html_erb__2888541332730611846_47144000' 

這個代碼是:

在rooms_controller.rb

class RoomsController < ApplicationController 
    respond_to :js, :html, :json 

    def index 
     @rooms = Room.all 
    end 
在模型

「room.rb」

class Room < ActiveRecord::Base 
    attr_accessible :capacity, :description, :is_active, :room_name 

    belongs_to :roometable, polymorphic: true 
    has_many :events 
end 

在routes.rb中

Glowfish::Application.routes.draw do 
    match '/calendar(/:year(/:month))' => 'calendar#index', :as => :calendar, :constraints => {:year => /\d{4}/, :month => /\d{1,2}/} 

    devise_for :users 

    resources :pages 
    resources :areas 
    resources :rooms 

    match '/:id' => 'high_voltage/calendar#index', :as => :static, :via => :get 
    root :to => 'high_voltage/calendar#index', :id => 'index' 
end 

意見>客房> index.html.erb

<h1>&nbsp;Rooms List <span class='pull-right'> <%= link_to "New Room", new_room_path, class: 'btn btn-primary' %> </span> </h1> 
<%= content_tag_for :div , room, class: 'row-fluid' do %> 
<div id="r-index_content"> 
<li> 
    <span class='span9' > 
    <%= link_to room.room_name, room ,{:style => 'color: #000000'} %> 
    </span> 
    <span class='span3'> 
    <span class='pull-right'> 
     <%= link_to "Edit", edit_room_path(room), class: 'btn btn-mini' %> 
     <%= link_to "Delete", room_path(room), method: :delete, data: { confirm: "Are you sure to delete this room?" }, class: 'btn btn-mini btn-danger' %> 
    </span> 
    </span> 
</li> 
</div> 
<% end %> 

我試圖解決這個問題,但沒有發生什麼是錯的。

請幫助我,謝謝你的時間來看看這個。

回答

0

你有沒有忘記添加迭代器?

<h1>&nbsp;Rooms List <span class='pull-right'> <%= link_to "New Room", new_room_path, class: 'btn btn-primary' %> </span> </h1> 
<% @rooms.each do |room| %> 
    <%= content_tag_for :div , room, class: 'row-fluid' do %> 
    ... 
<% end %> 
+0

好的,謝謝,我foget運作每個哈哈 –

1

看起來像你的roomnil這裏面的代碼:

content_tag_for :div , room, class: 'row-fluid' 
相關問題