Ruby on Rails
Thursday, May 28, 2015
<h1>Listing Assets for <%= asset.feature.try(:engtitle) %></h1>
If there are no assets, what is `asset` set to? Clearly it's set to nil right now, but what did you think it should be set to, and why?
<h1>Listing Assets for <%= @feature.try(:engtitle) %></h1>
What is the exception being raised here?
Please show the controller so we can tell what is being set up for the view.
On Thu, May 28, 2015 at 4:56 AM, DerAlSem <deralsem@gmail.com> wrote:
Hi,--I've list of features.
class Feature < ActiveRecord::Base
has_many :assets, dependent: :destroy
endand assets, that belongs to feature:
class Asset < ActiveRecord::Base
belongs_to :feature
validates :feature_id, presence: true
endi have one sample feature in db, and a link to show assets for this feature:
<td><%= link_to 'Show Assets', assets_path %></td>
Now, when i follow the link, list of assets is shown. Actually it is empty, as there are no assets in database. I need to show what feature this assets are belongs to (there're no assets, but that shouldn't make any difference).I've tried with this:
<h1>Listing Assets for <%= asset.feature.try(:engtitle) %></h1>getting
undefined local variable or method `asset' for #<#<Class:0xb4ce52e8>:0xb55c4440>and this
<h1>Listing Assets for <%= @feature.try(:engtitle) %></h1>raising exception, but there's definitely engtitle for this feature in database.What am i doing wrong?Thanks
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9e5125b8-84a0-4744-ac82-bb10c122bbe5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHUC_t8vtzAmsKQB5--0Ag%3DBgjTt9P_%2BpktNR0d%3DxJEbgSeaRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment