Confused about calling objects fields in Ruby -


Why do I get this error message? I am trying to make it so that the account name of each video is visible. Users and accounts are working perfectly on their own if I have not been included in it. Account_name, I just get an ugly collection code like: # I think I am confused about how to use an object's field within an object.

NoMethodError undefined method `account_name 'for video zero: NilClass

  & lt;% @ Video. Video |% & gt; & Lt; TR & gt; & Lt; Td> & Lt;% = video.file% & gt; & Lt; / Td> ** & lt; Td> & Lt;% = video.user.account_name% & gt; & Lt; / Td> ** & lt; TD & gt; & Lt;% = video.name% & gt; & Lt; / Td> & Lt; / TR & gt; & Lt;% end% & gt;    

apparently not with a video Users .

Change this:

  & lt; Td> & Lt;% = video.user.account_name% & gt; & Lt; / Td>   

To do this:

  & lt; Td> & Lt;% = video.user.try (: account_name)%> & Lt; / Td>    

Comments

Popular posts from this blog

python - how we can use ajax() in views.py in django? -

matlab - Using loops to get multiple values into a cell -

python - Sequence Pattern recognition with Pybrain -