开发者

Displaying fields dependent on SQL values in Rails Views

开发者 https://www.devze.com 2023-02-11 08:12 出处:网络
was wondering if anyone can help me. I\'m just starting ou so this may seem a bit mundane to some people. I

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 %> 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号