On Nov 9, 2009, at 4:21 PM, christian wrote:

> Thank you so much for your responses. I really appreciate the help  
> this community provides for people trying to understand. It really  
> helps me fill in the gaps of what I am reading from the available  
> tutorials. (Is there a full copy of the book available? It seems  
> only to go up to chapter 4)
>
>   Assign your finder to @submissions (or even self.this) and
> then reference in the view.
>
> So I can assign found values to @something in the controller and  
> then call them into tables when I need them?
> (ex: def account
>       hobo_show
>      @prose = Submission.find(:all, :conditions => ["users.genre  
> = ?", "Prose"],
>      end)
> Then do a <table-plus with="@prose"...?
>
> I was going to attempt to do something similar with 'this' but I  
> wanted to split the page between roles and call different table-plus  
> tables for each user . I would rather learn to do it the right way  
> rather than just a way that works so any information or link to a  
> tutorial would be appreciated.

Almost - but you'll definitely want to put the find call either before  
hobo_show or inside a block passed to hobo_show, lest you run around  
in circles for a while trying to figure out why the action fires, the  
DB call is made, but nothing shows up. Not that *I've* ever done that  
or anything... ;)

You may also want to consider defining the search you've got there as  
a scope:

class Submission
   named_scope :prose, :include => :users, :conditions => { :users =>  
{ :genre => 'Prose' } }
end

If you really wanted to get fancy, you could even generate a whole  
bunch of these dynamically (assume User defines a GENRES constant):

class Submission
   User::GENRES.each do |g|
     named_scope g.underscore, :include => :users, :conditions =>  
{ :users => { :genre => g } }
   end
end

Then your find call reduces to:

@prose = Submission.prose.all

and you can use all the usual spiffyness (paginate, etc) against  
Submission.prose as well.

Even better, if you needed to you could have an index action on  
SubmissionsController like this:

class SubmissionsController
   hobo_model_controller
   index_action :prose, :scope => :prose
end

Named scopes are definitely my favorite Rails feature, and Hobo makes  
them even better. Although going back to plain Rails always trips me  
up when I try to use automatic scopes that don't exist there...

--Matt Jones


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to