lieven
1
I have following code in my controller:
class AlbumsController < ApplicationController
def list_by_year(year)
@album_pages
@albums = paginate :albums,
{ :per_page => 10,
:conditions => [“year = ?”, year] }
render :action => ‘list’
end
end
Now I want to make a link to the list_by_year action in show.rhtml
<%= link_to @album.year,
{ :action => ‘list_by_year’ },
{},
@album.year %>
Isn’t this what the *parameters_for_method_reference is for? Obviously
not because I get:
wrong number of arguments (0 for 1)
What is the correct way to pass this parameter? Haven’t found anything
by googling.
lieven
2
Lieven De Keyzer wrote:
I have following code in my controller:
class AlbumsController < ApplicationController
def list_by_year(year)
@album_pages
@albums = paginate :albums,
{ :per_page => 10,
:conditions => [“year = ?”, year] }
render :action => ‘list’
end
end
Now I want to make a link to the list_by_year action in show.rhtml
<%= link_to @album.year,
{ :action => ‘list_by_year’ },
{},
@album.year %>
Isn’t this what the *parameters_for_method_reference is for? Obviously
not because I get:
wrong number of arguments (0 for 1)
What is the correct way to pass this parameter? Haven’t found anything
by googling.
I don’t think you can pass parameters this way.
You can submit it through the params hash like this
class AlbumsController < ApplicationController
def list_by_year
year = params[:year]
@album_pages,
@albums = paginate :albums,
{ :per_page => 10,
:conditions => [“year = ?”, year] }
render :action => ‘list’
end
end
<%= link_to @album.year,
{ :action => ‘list_by_year’ },{:year => @album.year} %>