ruby on rails - Heroku issue, ActionView::Template::Error (undefined method `name' for nil:NilClass): -


loading without problem on localhost:3000, once deployed heroku receiving following error. ran

heroku logs --tail  2013-08-29t04:38:23.403690+00:00 app[web.1]: connecting database specified database_url 2013-08-29t04:38:26.898295+00:00 app[web.1]: [2013-08-29 04:38:26] info  webrick 1.3.1 2013-08-29t04:38:26.898295+00:00 app[web.1]: [2013-08-29 04:38:26] info  ruby 2.0.0 (2013-06-27) [x86_64-linux] 2013-08-29t04:38:26.898634+00:00 app[web.1]: [2013-08-29 04:38:26] info  webrick::httpserver#start: pid=2 port=11226 2013-08-29t04:38:27.010520+00:00 heroku[web.1]: state changed starting 2013-08-29t04:38:28.496863+00:00 app[web.1]: started "/" 50.148.15.124 @ 2013-08-29 04:38:28 +0000 2013-08-29t04:38:28.642277+00:00 app[web.1]: processing eventscontroller#index html 2013-08-29t04:38:29.529140+00:00 heroku[router]: at=info method=get path=/ host=afternoon-gorge-1648.herokuapp.com fwd="50.148.15.124" dyno=web.1 connect=5ms service=1081ms status=500 bytes=643 2013-08-29t04:38:29.541662+00:00 app[web.1]:   rendered events/_event.html.erb (320.3ms) 2013-08-29t04:38:29.541795+00:00 app[web.1]:   rendered events/index.html.erb within layouts/application (743.9ms) 2013-08-29t04:38:29.542093+00:00 app[web.1]: completed 500 internal server error in 900ms 2013-08-29t04:38:29.544607+00:00 app[web.1]:  2013-08-29t04:38:29.544607+00:00 app[web.1]: actionview::template::error (undefined method `name' nil:nilclass): 2013-08-29t04:38:29.544607+00:00 app[web.1]:     3:   <td><%= event.title %></td> 2013-08-29t04:38:29.544607+00:00 app[web.1]:     4:   <td><%= event.location %></td> 2013-08-29t04:38:29.544607+00:00 app[web.1]:     5:   <td><%= event.description %></td> 2013-08-29t04:38:29.544607+00:00 app[web.1]:     6:   <td><strong><%= link_to event.user.name, event.user %></strong></td> 2013-08-29t04:38:29.544607+00:00 app[web.1]:     7:   <td><%= link_to 'show', event %></td> 2013-08-29t04:38:29.544607+00:00 app[web.1]:     8:   <% if current_user == event.user %> 2013-08-29t04:38:29.544607+00:00 app[web.1]:     9:     <td><%= link_to 'edit', edit_event_path(event) %></td> 2013-08-29t04:38:29.544607+00:00 app[web.1]:   app/views/events/_event.html.erb:6:in `_app_views_events__event_html_erb___4373324357052961172_69914882818260' 2013-08-29t04:38:29.544790+00:00 app[web.1]:   app/views/events/index.html.erb:20:in `_app_views_events_index_html_erb___3028579038251132182_69914889655380' 2013-08-29t04:38:29.544790+00:00 app[web.1]:   app/controllers/events_controller.rb:9:in `index' 

i have confirmed databases locally , on heroku match. app fails when logged in. landing page loads fine when logged out. happened when added new 7 new user fields database, strings. ran

rake db:migrate  

locally.

ran

heroku run rake db:migrate. 

here heroku link: http://afternoon-gorge-1648.herokuapp.com/

very confused problem lies.

update: here events index page:

<% if user_signed_in? %>   <div class="hero-unit">     <h1>sign of following events!</h1>   </div>   <h1>listing events</h1>   <table class="table table-striped">     <thead>       <tr>         <th>image</th>         <th>title</th>         <th>location</th>         <th>description</th>         <th>posted by</th>         <th></th>         <th></th>         <th></th>       </tr>     </thead>     <tbody>      <%= render @events %>     </tbody>   </table>   <br/>   <%= link_to 'add new event', new_event_path, class: "btn btn-primary btn-large" %> <% else %>   <%= render 'pages/home' %> <% end %>  

calls _event.html.erb partial:

<tr>   <td><%= image_tag event.image(:medium) %></td>   <td><%= event.title %></td>   <td><%= event.location %></td>   <td><%= event.description %></td>   <td><strong><%= link_to event.user.name, event.user %></strong></td>   <td><small><%= link_to 'show', event %></small></td>   <% if current_user == event.user %>     <td><small><%= link_to 'edit', edit_event_path(event) %></small></td>     <td><small><%= link_to 'delete', event, method: :delete, data: { confirm: 'are sure?' } %></small></td>   <% end %> </tr> 

you're attempting invoke render partial shorthand. however, shorthand can used singular objects, you're trying pass _a collectio_n of objects. instead, need loop through @events , pass each resulting event local partial:

# app/views/events/index.html.erb <% @events.each |event| %>         <%= render :partial => 'events', :locals => {:event => event} %> <% end %> 

to understand more regarding why syntax you've invoked doesn't work, see section 3.4.4 passing local variables in rails guides. basically, _event.html.erb partial expecting singular object (which would access via event local variable), instead, you're passing collection of multiple event objects. so, while local variable events available partial, event isn't.

since you're still trying access attributes/relations on event variable (which doesn't exist) you're receiving nilclass error. thus, looping through each event , explicitly passing event partial should resolve error.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -