form_for and scopes, rails 3

前端 未结 7 2094
执念已碎
执念已碎 2020-12-19 05:37

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
         


        
7条回答
  •  太阳男子
    2020-12-19 06:14

    In a very similar situation I defined the scope in routes like below:

    scope :path => ":election_id", :as => "election" do 
      resources :questions
    end
    

    Now I have helpers like election_questions_path(@election)

    In the forms I can use:

    form_for [@election, @question] do |f|
      ...
    end
    

    In above examples @election is an instance of the Election model.

    After integrating Friendly_id into this solution I got some pretty urls. For example "http://mydomain.com/elections-2012/questions/my-question"

提交回复
热议问题