The following is a kludge to generate a drop down list of the rows for the "categories" table (from the "Category" model). thufir@arrakis ~/Desktop/strawr $ thufir@arrakis ~/Desktop/strawr $ tail app/views/feeds/show.rhtml -n 2 <%= select(:category, :id, Category.find(:all).collect {|c| [ c.category, c.id ] } ) %> thufir@arrakis ~/Desktop/strawr $ However, I''d rather put a method in feeds_controller.rb if that''s possible. Would that be a better way to generate the drop down list? thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 26 Dec 2007, at 09:25, Thufir wrote:> > The following is a kludge to generate a drop down list of the rows for > the "categories" table (from the "Category" model). > > thufir@arrakis ~/Desktop/strawr $ > thufir@arrakis ~/Desktop/strawr $ tail app/views/feeds/show.rhtml -n 2 > > <%= select(:category, :id, Category.find(:all).collect {|c| > [ c.category, > c.id ] } ) %> > thufir@arrakis ~/Desktop/strawr $ > > > However, I''d rather put a method in feeds_controller.rb if that''s > possible. Would that be a better way to generate the drop down list? >If you want to wrap this up in a method put it in feeds_helper.rb Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Wed, 26 Dec 2007 12:00:39 +0000, Frederick Cheung wrote:> If you want to wrap this up in a method put it in feeds_helper.rbI''ve done an admittedly brief google and haven''t found much. Am I on the right track? http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you want the helper to be available to all templates in the app, define it in application_helper.rb otherwise define it in category_helper.rb. On Dec 26, 2007 1:25 AM, Thufir <hawat.thufir-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > However, I''d rather put a method in feeds_controller.rb if that''s > possible. Would that be a better way to generate the drop down list? > >-- http://www.rubyplus.org/ Free Ruby and Rails Screencasts --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
PLEASE! Do not put model code in the view. It''s like putting onion in ice cream. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 26, 3:04 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> PLEASE! Do not put model code in the view. It''s like putting onion in ice > cream.I''m not clear on what you mean. The attributes/fields for the model are defined at http://strawr.googlecode.com/svn/trunk/db/migrate/002_feeds.rb, not really in http://strawr.googlecode.com/svn/trunk/app/models/feed.rb. However, I suppose that''s still within the "model" for MVC. The point is to have the drop-down list at http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml give the same result as>> Category.find :all=> [#<Category:0xb700b90c @attributes={"category"=>"some category", "id"=>"1"}>] does from script/console, albeit without the hexadecimal. I understand the generalities, that in MVC the different parts are intentionally not overlapping. Yes, the view should stay with view stuff. Concretely, what do you mean? -Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You''re doing a Model.find request in the model. This should be done in the controller. There should be no going back to the database when it''s trying to render views. -- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Wed, 26 Dec 2007 12:41:56 -0800, Bala Paranj wrote:> If you want the helper to be available to all templates in the app, > define it in application_helper.rb otherwise define it in > category_helper.rb.Yes, I want to edit <http://strawr.googlecode.com/svn/trunk/app/helpers/ application_helper.rb> to, umm, help the controller(s) list the categories through the various show.rhtml''s, but in a correct, non-kludgy way. Pardon, no I haven''t done much research into how to do that specific operation, but could I have some direction as to how to do that? I want to render the views without going back to the database. thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 26, 4:00 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: [...]> If you want to wrap this up in a method put it in feeds_helper.rb[...] I would like to wrap the it up in a method in application_helper.rb but don''t from reading http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html and other sources don''t know what method to create. I want a drop down list for the model http://strawr.googlecode.com/svn/trunk/app/models/category.rb to replace the kludge to generate that list, as it''s currently done, at http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml . How does the method in application_helper.rb get "called"? thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 29 Dec 2007, at 04:18, Thufir wrote:> > On Dec 26, 4:00 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > [...] >> If you want to wrap this up in a method put it in feeds_helper.rb > [...] > > > I would like to wrap the it up in a method in application_helper.rb > but don''t from reading > http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html > and other sources don''t know what method to create. > > I want a drop down list for the model http://strawr.googlecode.com/svn/trunk/app/models/category.rb > to replace the kludge to generate that list, as it''s currently done, > at http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml . > > > How does the method in application_helper.rb get "called"?You can put whatever you want in feeds_helper, application helper etc... Those modules are included in view templates as appropriate. So if you have module FeedsHelper def my_helper end end You can do <%= my_helper %> in your view. From a helper you can call all the helper functions you normally have access to. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 29, 4:48 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: [...]> So if you have > module FeedsHelper > def my_helper > end > end > > You can do <%= my_helper %> in your view. From a helper you can call > all the helper functions you normally have access to. > > FredThanks, Fred, that helps quite a bit. Something like: module FeedsHelper def list_categories Category.find(:all) end end -Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 29 Dec 2007, at 23:43, Thufir wrote:> > On Dec 29, 4:48 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > [...] >> So if you have >> module FeedsHelper >> def my_helper >> end >> end >> >> You can do <%= my_helper %> in your view. From a helper you can call >> all the helper functions you normally have access to. >> >> Fred > > Thanks, Fred, that helps quite a bit. Something like: > > module FeedsHelper > def list_categories > Category.find(:all) > end > end > >You''re on the way there. If it was me then I''d have a method on categories that did the find for me, with the right conditions etc... Then in Feeds Helper i''d have def select_category select :category, :id, Category.some_find_method.collect {|c| [ c.category, c.id ] end Fred> > > -Thufir > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, 30 Dec 2007 08:14:43 +0000, Frederick Cheung wrote:> def select_category > select :category, :id, Category.some_find_method.collect {|c| > [ c.category, c.id ] > endI think that I would get better results if I tried to do this at three pm instead of three am! Ok, I got it working, but it feels equally kludgy: thufir@arrakis ~/Desktop/strawr $ thufir@arrakis ~/Desktop/strawr $ cat app/helpers/application_helper.rb # Methods added to this helper will be available to all templates in the application. module ApplicationHelper def select_category # select :category, :id, Category.some_find_method.collect {|c| [ c.category, c.id ]} select :category, :id, Category.find(:all).collect {|c| [ c.category, c.id ]} end end thufir@arrakis ~/Desktop/strawr $ thufir@arrakis ~/Desktop/strawr $ tail app/views/feeds/show.rhtml -- lines=1 <%= select_category %> thufir@arrakis ~/Desktop/strawr $ However, that achieves the purpose. I think what bothers me, slightly, is the complexity of the compound line in the select_category method. I can read it, sorta, but can''t write it :( However, I''ll live :) Oh, now I get it. I must be tired. I need to define a few "some_find_method"''s, like: categories linked to this feed, categories not linked to this category, etc. These methods are in the same module? I was thinking of refining the query from all records to just those records which are linked to the particular object. However, since I have trouble writing that in English, I''ll take a pass and come back to that. I would like have two buttons: "link" and "unlink". When "link" is clicked then a row the "tags" table (horrible name) is created with the feeds_id and categories_id values. (If it creates the same relationship ten times, that''s ok for now). The unlink would delete the corresponding row from the "tags" table. I followed the Apple demo and created http://code.google.com/p/ expenses/ , which has buttons kind-of along this line. However, it''s a one-to-many wheras I want a many-to-many. Plus, I think that the Apple tutorial is more than a little dated. Just thinking outloud. What kind of button would be sufficient for what I describe? I''m a bit more confident with how the show.rhtml interacts with methods, but: which method in which class for a "submit" type button? where does the button go? Just thinking out loud, and will be googling tomorrow :) -Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, 30 Dec 2007 08:14:43 +0000, Frederick Cheung wrote:> If it was me then I''d have a method on categories that did the find for > me, with the right conditions etc...Right; for now it''s ok and I want to move forward. In which file would you put this query? thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---