I''m a beginner, i have created for my web application 2 tables "videos" and "category". I want to create a controller for display all videos by category, for do that i write a Category controlle rwith this ACTION def index @temp = 1 @video_pages, @videos = paginate :videos, :conditions => [''category_id = ?'', @temp], :per_page => 10, :order => "videos.created_at desc" end I want to display the category pages by submit the category id directly in the URL ( the link to category page must be similar to ''/category/1''. My problem is that when i submit the category id in this way, the Category controller return an error message: Uknown Action i tried to reassign the category id in this way: @temp = params[:id] but don''t work in any way Thanks in advance -- 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 -~----------~----~----~----~------~----~------~--~---
I tried this code:> def index > @temp = 1 > @video_pages, @videos = paginate :videos, > :conditions => [''category_id = ?'', @temp], > :per_page => 10, > :order => "videos.created_at desc" > end >this work good and display all videos in category 1 but this: class CategoryController < ApplicationController def index @temp = params[:id] @video_pages, @videos = paginate :videos, :conditions => [''category_id = ?'', @temp], :per_page => 10, :order => "videos.created_at desc" end don''t work -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, I think this has to do with the fact that your URL format is incorrect, so rails is think that you are calling the function titled ''1'' and so never passing the ID to the function index to be stored in the @temp variable. This is not what you want ? Try calling it through the browser using /catergory/index/1. This should correctly break up the URL using the format /[controller name]/[method to invoke]/parameters. I hope this helps. Dexter Enrico Ee wrote:> > I tried this code: > >> def index >> @temp = 1 >> @video_pages, @videos = paginate :videos, >> :conditions => [''category_id = ?'', @temp], >> :per_page => 10, >> :order => "videos.created_at desc" >> end >> > > this work good and display all videos in category 1 > > but this: > > class CategoryController < ApplicationController > > def index > @temp = params[:id] > @video_pages, @videos = paginate :videos, > :conditions => [''category_id = ?'', @temp], > :per_page => 10, > :order => "videos.created_at desc" > end > > don''t work-- 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 -~----------~----~----~----~------~----~------~--~---