views:

24

answers:

3

Hi I have a problem due to scopes and the form_for helper in rails 3. The routes - file looks like this:

scope "(/:tab)" do
  resources :article
end

The form looks something like this:

<%= form_for(@article) %>
   <%= f.label :title %>
   <%= f.text_field :title %>
    etc.
<%end%>

The tab - attribute is stored in params[:tab], as a string My problem is that this genereate wrong urls in the form. How could I get this to work ? The genreated url article_path(params[:tab], @article) works perfectly fine

A: 

You could specify the path explicitly:

<%= form_for(@article, :url => article_path(@article, :tab => params[:tab]) %>
Matt Haley
This seems to work nice on the edit - part, but if I want to use the same form for both new and edit, it fails with the following error in new because the new article has no id
furien
A: 

Try:

<%= form_for [:tab, @article] do |f| %>
   <%= f.label :title %>
   <%= f.text_field :title %>
    etc.
<%end%>
Yannis
Then it looks for the tab_article_path which is not defined.
furien
What are the routes generated by your routes.rb file? try "$ rake routes" in a terminal
Yannis