Reputation: 2849
I have a model and for some reason I am trying to tell rails if there is nothing created then render add a new show link.
<% if @show != blank? %>
<%= link_to 'Add a new show', new_show_path %></br>
<% else %>
<%= render(:partial => 'shows/show', :locals => {:show => @profile.shows.last}) %>
<% end %>
It adds the Add a new show link but once a show is created I still only see the link and not the partial. If I create the show and put the render at top like so then I can see it but if i delete the show it returns an error.
I've tried these also
<% if @show.present? %>
<%= render(:partial => 'shows/show', :locals => {:show => @profile.shows.last}) %>
<% else %>
<%= link_to 'Add a new show', new_show_path %></br>
<% end %>
<% if @show.blank? %>
<%= link_to 'Add a new show', new_show_path %></br>
<% else %>
<%= render(:partial => 'shows/show', :locals => {:show => @profile.shows.last}) %>
<% end %>
<% if #{model} nil? %>
<%= link_to 'Add a new show', new_show_path %></br>
<% else %>
<%= render(:partial => 'shows/show', :locals => {:show => @profile.shows.last}) %>
<% end %>
and it seems to never give me what I am looking for on both ends. It ethiers shows me the link and nevers shows the partial once created or it shows the partial but when I delete it it gives me an error.
How can I tell rails that if there is no shows created to render the add new link and once there is a show created to render the partial?
Upvotes: 0
Views: 393
Reputation: 11
Use the .blank? method for the global variable you're trying to tell if it's empty. If its an array or hash. Use .nil? If its supposed to be anything else.
Upvotes: 0
Reputation: 4807
Are you actually filtering this by profile? It looks like you're rendering a page for the last show of a profile. (@profile.shows.last
)
<% show = @profile.shows.last %>
<% if show.blank? %>
<%= link_to 'Add a new show', new_show_path %>
<br />
<% else %>
<%= render 'shows/show', :show => show %>
<% end %>
Upvotes: 1