ruby on rails - Impossible to acces to value in database -
i'm rails newbie !
i know why in different case, 1 work, 1 doesn't.
### in controller ### def watch_randurl # @dat = video.where(url_rand: params[:url_rand]) @dat = video.find(1) end
with find(1)
, have database , in view work!
### in view ### <%= @dat.url_rand %> <br>
but where
have undefined method 'url_rand' <video::activerecord_relation:0x007fcbfeece1c8>
ps: sorry english :/ of course, need work where.
solve : video.where(url_rand: params[:url_rand]).first
thank !
but have undefined method 'url_rand' video::activerecord_relation:0x007fcbfeece1c8
where
returns activerecord_relation
, in case, need modify @dat = video.where(url_rand: params[:url_rand])
, @dat = video.where(url_rand: params[:url_rand]).first
or
you can iterate on @dat
below, without changing value of @dat
<% @dat.each |dat| %> <%= dat.url_rand %> <br> <% end %>
Comments
Post a Comment