Displaying fields dependent on SQL values in Rails Views
was wondering if anyone can help me. I'm just starting ou so this may seem a bit mundane to some people. I have a view which I need to display certain fields if a particular value is selected in the database. The example is similar to a blog post where you may or may not want to show a source link. So in the backend there is a tick box which is attached to a sql boolean value then if that is ticked you can also put the link in for the source location.开发者_开发技巧 On the front end however if the boolean is set to false I don't want to display the data in that field. What's the best way of going about this?
You can use conditionals in erb views.
For example:
<% if @v == 4 %>
<p>v is equal 4.</p>
<% else %>
<p>v isn't equal 4.</p>
<% end %>
精彩评论