2

I have a partial in Rails.

View:

<%= render :partial => "partial" %>

Partial:

<% if no_entries %>
    <h1>No entries</h1>
    <% return %>
<% end %>

<!-- Display entries -->

When I run this partial with an error, the output is blank. How can I make it display the <h1>?

NOTE: In my actual code, I want to return multiple lines and I am trying to avoid an if else end with a thousand lines in between the else and end.

Thanks!

Dan Grahn
  • 9,044
  • 4
  • 37
  • 74
  • When you say the output is blank, do you mean the entire page? If that's the case I'd suspect it to be the return statement. – spullen Jul 01 '13 at 15:30
  • The output from the partial is blank. And yes, it is the return statement. I am looking for the correct code to return with the content. – Dan Grahn Jul 01 '13 at 15:34
  • You could try `<% if flash[:error] %>

    Error!

    <% end %>`
    – spullen Jul 01 '13 at 15:40
  • It looks like your if statement, `if error`, is returning false if you don't see the `

    ` tag. Where are you defining `error`? Also, try putting `

    Error!

    ` outside the if statement to see if you are calling the partial correctly.
    – Huy Jul 01 '13 at 15:52
  • This isn't about the partial having a problem, or about display an error. i know how to do both of those. The code above is for demonstration of what I would like to do, which is: return content from a partial without executing any of the remaining code. – Dan Grahn Jul 01 '13 at 16:28

0 Answers0