On Sat, Oct 9, 2010 at 11:13 AM, Anders_P <[email protected]> wrote:
> Hi! Thanks for your help. But I still doesn't get it to work. I've > changed the controller action so it looks like: > > def category > gender = params[:gender] > category = params[:category] > @ads = Ad.find_all_by_gender_and_category(gender, > category).paginate(:page => params[:page]) > @title = "Startsidan" > render 'home' > end > > And in the view: > > <li class="li_content"><%= link_to "Accessoarer", :action => > 'category', :gender => 'female', :category => 'Accessoarer' %></ > li><br /> > > When I press the link the url changes to this: > > http://localhost:3000/kategori?gender=female&category=Accessoarer > > I don't get any errors, but it doesn't find anything. Any idea on what > might be wrong? > So you are rendering the 'home' view - can you show me this? Also, describe what you are expecting to see. Have you also verified that you are getting good values on @ads and @title (which I assume you are doing something with in your view)? I would recommend if you have not used it yet to get familiar with ruby-debug. This way you can step in to your controller in action and check these attributes (of course even better is get used to writing tests for your code, but I know this might be overwhelming at first). Let me know - if you need help with ruby-debug let me know --- if so do give me the version of Rails and version of Ruby you are running. > > // Anders > > > On 9 Okt, 17:23, David Kahn <[email protected]> wrote: > > On Sat, Oct 9, 2010 at 7:41 AM, Anders_P <[email protected]> > wrote: > > > Hello! > > > > > I'm trying to create a menu. I have a controller that takes two > > > attributes, like this: > > > > > def category(gender, category) > > > @ads = Ad.find_all_by_gender_and_category(gender, > > > category).paginate(:page => params[:page]) > > > @title = "Startsidan" > > > render 'home' > > > end > > > > Is this your controller code? If so you have issues as (someone correct > me > > if this is a new Rails 3 construct that I am clueless) you should not be > > taking arguments in the signature. If the params gender and category are > > needed they should be accessed as params[:gender] params[:category]. > > > > So in your view you need something like this below. Also seehttp:// > apidock.com/rails/ActionView/Helpers/UrlHelper/link_tofor info on > > link_to helper. > > > > <%= link_to "Accessories", :controller => "categories", :action => > "show", > > :gender => "male", :category => "zzz" > > > > and then in your controller action > > > > def show > > gender = params[:gender] > > category = params[:category] > > # now do what you want with the data > > end > > > > David > > > > > > > > > And in my view I have a list with menu options: > > > > > <li class="li_content"><%= link_to "Accessoarer", :action => > > > "category('dam', 'Accessoarer')" %></li><br /> > > > > > And my routes it look like this: > > > > > match '/dam-accessoarer', :to => "pages#category('dam', > > > 'Accessoarer')" > > > > > But it doesn't work. > > > > > I get the following error. > > > > > Unknown action > > > > > The action 'category('dam', 'Accessoarer')' could not be found for > > > PagesController > > > > > Any help on how to solve it would be greatly appreciated! > > > > > Thanks! > > > // Anders > > > > > -- > > > 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 [email protected] > . > > > To unsubscribe from this group, send email to > > > [email protected]<rubyonrails-talk%[email protected]><rubyonrails-talk%2Bunsubscrib > [email protected]> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]<rubyonrails-talk%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

