Forum: Ruby on Rails find_by_sql + partials question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C204883ecbdf04c9a5bc9b024f5ed575?d=identicon&s=25 Bill Pennington (Guest)
on 2006-01-11 00:56
(Received via mailing list)
Ok now that I have find_by_sql love working for my "Top 10 List" I
want to make them a bit more DRY. Tis is what I have so far:

Model:

     def self.topfish
       find_by_sql["select species.name,
length,species.multiplier*length as score,caught_on from entries join
species on species_id = species.id where species_id = ? order by
score DESC LIMIT 10", species]
     end

This data is spit out as part of a partial:

Partial:

<% for ling in @topfish %>
<table border ="0" CELLSPACING="0">
<tr class="<%= alternate %>">
   <td><%=h ling.name %> - </td>
   <td><%=h ling.length %> Inches - </td>
   <td><%=h ling.score %> Points - </td>
   <td><%=h ling.caught_on.strftime("%m-%d-%Y") %></td>
</tr>
<% end %>

Main Viw:

<div id="topfish">
	<%= render :partial => 'topfish', :locals => { :species => "1" } %>
</div>


Controller:

   def list
     @entries = Entry.mine
     @topfish = Entry.topfish
   end

Now when I load the list I get this - "wrong number of arguments (0
for 1)" So I know I need to pass a species_id in with my partial bu
it does not appear to work with locals. Any pointers would be
helpful, I have spent the last few hours hunting around but I can't
figure out why this is not working.

What I want to do is pass a variable in to the find_by_sql using a
local in the main view. This way I can update that when a new fish is
added in a given species.



- Bill
This topic is locked and can not be replied to.