Hello, I''m very new at rails. I''m making a simple blog made up of entries. I have an entry model and a category model. Obviously, each category will have many entries, and each entry will be in a category. I have a select box that submits a category_id to my controller. How can I use this category_id to only show entries that have that category_id? Here''s what I have so far, which just returns nothing: def list @entry_pages, @entries = paginate :entries, :per_page => 10, :order_by => ''date desc'' @categories = Category.find_all end def show_by_cat cat_id = params[:entry] @entry_pages, @entries = paginate :entries, :per_page => 10, :conditions => ["category_id = ?", cat_id], :order_by => ''date desc'' render :action => ''list'' end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Here''s the form that generates the select list: <% form_for :entry, :url => { :action => ''show_by_cat'' } do |form| %> <%= form.collection_select(:category_id, @all_cats, :id, :name)%> <%= submit_tag ''Go'' %> <% end %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try trying changing params[:entry] to params[:entry][:category_id]. Just to note, it''s probably best to not use form_for in this instance as you are not dealing directly with a model. I would rework this to something like this: <% form_tag :action => ''show_by_cat'' do %> <select name="category_id"> <%= options_from_collection_for_select(@all_cats, :id, :name)%> </select> <%= submit_tag ''Go'' %> <% end %> Then in your controller: category_id = params[:category_id] Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That worked perfect! Thanks so much for your help and your advice! I''ll definitely try the change you suggested. Thanks again Jason -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---