Sunday, 15 June 2014

database - Ruby on Rails how to get last query? -



database - Ruby on Rails how to get last query? -

i'm having problem trying figure out when reached end of query. want list records in database begin letter got want output message if query turns out blank. when seek bunch of custom messages query didn't turn out blank. there way tell if i've reached eof in ruby on rails?

sample

<div id = "content-a"> <p>a</p> <% @animes.each |anime| %> <% if anime.aname.starts_with?('a') %> <%= link_to anime.aname, {:action => 'list'} %> <% else %> <p>no anime listed in category :( </p> <%end%> <%end %> </div>

i believe want sth like:

<% animes_group = @animes.group_by {|anime| anime.aname.to_s[0].upcase} ('a'..'z').each |letter| %> <div id="content-<%= letter %>"> <p><%= letter %></p> <% if animes = animes_group[letter] %> <% animes.each |anime| %> <%= link_to anime.aname, {:action => 'list'} %> <% end %> <% else %> <p>no anime listed in category :( </p> <%end%> <% end %>

you should consider moving of logic controller here, moved depends on many factors whether @animes beingness used anywhere else etc.

ruby-on-rails database

No comments:

Post a Comment