"Not Available" Rails
Dear All, When I use a table from database, if data is not available in table. I will use if and else conditions like
<% if @tables.blank? %>
<p> Not available</p>
<% else %>
blaaa blaa
<% end %>
It works fine. Now I need to apply the same thing for connected tables. If data is available in first table tables and not available i开发者_如何学Cn benches. How I can apply??
I tried like this
<% @tables.each do |table| %>
<% if table.benches.blank? %>
<p> Not available</p>
<% else %>
blaaa blaa
<% end %>
<% end %>
... But its not working. Kindly give me suggestions.
I'm not quite sure what you want, but maybe this will help you.
<% if @tables.blank? %>
<p> Not available</p>
<% else %>
<% @tables.each do |table| %>
<% if table.benches.blank? %>
<p> Not available</p>
<% else %>
blaaa blaa
<% end %>
<% end %>
<% end %>
Try using #empty?
.
<% @tables.each do |table| %>
<% if table.benches.empty? %>
<p> Not available</p>
<% else %>
blaaa blaa
<% end %>
<% end %>
What happens if you try this:
<% unless table.benches.exists? %>
<p> Not available</p>
<% else %>
blaaa blaa
<% end %>
if/else
must output one or the other... make sure you check your HTML source code (not just browser view) to see if the output isn't hiding somewhere inside a tag.
Dear All, Its working... when i apply like this...
<% if @tables.blank? %>
<p> Not available</p>
<% else %>
<% @tables.each do |table| %>
<% table.benches.each do |bench| %>
<% if bench.column.blank? %>
<p> Not available</p>
<% else %>
blaaa blaa
<% end %>
<% end %>
<% end %>
<% end %>
Thank you for everyone who participated in this Question.
精彩评论