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
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
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