ruby on rails - NoMethodError in Flights#show -


showing app/views/flights/show.html.erb line #3 raised:

you have nil object when didn't expect it! error occurred while evaluating nil.name  extracted source (around line #3):  1: <p> 2:  <b>airline name:</b>  3:  <%= @flight.airline.name %> 

well above error occurring when trying submit 'seat' form.

i have '_new_seat' 'partial' page in flights/show. when clicking on 'book new seat'(submit), should redirect seats/show, doesn't..

whether requires method in flights controller?.. please me.

your @flight not have airline associated.

to off error when there no airline associated, write:

@flight.airline.try(:name) 

to have airline associated. check @flight object properties.

first, check have this:

class flight < activerecord::base   belongs_to :airline 

second, have airline_id correctly set in flight instance.

third, have airline airline_id saved in airlines table.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -