nums nums - 5 months ago 12
Ruby Question

Rails NoMethodError in Albums#show

I'm trying to show a link to a new description if an album doesn't currently have a description, but I keep getting a NoMethodError:

<% if @album.description.size = 0 %>
<div class="new-description"><%= link_to 'Add Description', "/albums/#{x.id}/edit" %></div>
<% else %>
<div class="description"><%= @album.description %></div>
<% end %>

Answer

This should also work, provided description is supposed to be a string.

<% if not @album.description.nil? %>
    <div class="new-description"><%= link_to 'Add Description', "/albums/#{x.id}/edit" %></div>
<% else %>
    <div class="description"><%= @album.description %></div>
<% end %>