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 %>
<%=h ling.name %> - |
<%=h ling.length %> Inches - |
<%=h ling.score %> Points - |
<%=h ling.caught_on.strftime("%m-%d-%Y") %> |
<% end %>
Main Viw:
<%= render :partial => 'topfish', :locals => { :species => "1" } %>
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.