ruby-on-railsrubyrhtml

Simple question about an if block in Ruby on Rails


I am trying to tell ruby to not run a block of html and ruby if no active record exists in the database. Below is the code I was trying to run conditions on.

<% if @statemant.comments.exists?() do %>  
<div id="comments">  
<h2>Comments</h2>  
<%= render :partial => @statemant.comments %>  
</div>  
<% end %>    

Solution

  • You need to get rid of the do from your if statement (you can optionally replace it with then). do is used for blocks. if isn't a function, so it doesn't take a block.