Jump to content

The ultimate community for Ruby on Rails developers.


Photo

form_for and nested routes

routing form_for helper

  • Please log in to reply
1 reply to this topic

#1 fonov.ivan

fonov.ivan

    Passenger

  • Members
  • 1 posts

Posted 21 November 2013 - 09:19 PM

Hello guys.

 

My rails verion 4.0.1; ruby version 2.0.

 

Can you help me with rails rounting system and form_for helper?

 

Description:

 

config/routes.rb

namespace :forum, path: '' do
  resources :topics, path: 'themes' do
    resources :replies, only: [:new, :create, :edit, :update]
  end
end

rake routes CONTROLLER=forum/replies

forum_topic_replies   POST/themes/:topic_id/replies(.:format)         forum/replies#create
new_forum_topic_reply  GET/themes/:topic_id/replies/new(.:format)     forum/replies#new
edit_forum_topic_reply GET/themes/:topic_id/replies/:id/edit(.:format)forum/replies#edit
forum_topic_reply    PATCH/themes/:topic_id/replies/:id(.:format)     forum/replies#update
                     PUT  /themes/:topic_id/replies/:id(.:format)     forum/replies#update

As you can see create action  avaliable by forum_topic_replies_path method.

 

Then I try to use [topic, reply] objects inside form_for(haml):

= form_for([topic, reply]) { |f| }

I am got error: undefined method `forum_topic_forum_replies_path' for #<#<Class:0x007f53bebf63c8>:0x007f53bebf5130>

 

topic - persisted object

reply - not persisted object

 

Why form bulder try to use forum_topic_forum_replies_path but not forum_topic_replies_path 

 

How I can fix that  behaviour?

 

Thanks a lot.



#2 Bruce Wayne

Bruce Wayne

    Passenger

  • Members
  • 1 posts

Posted 06 December 2013 - 12:14 PM

I would like to thank you for the efforts you have made in writing this post. your provided information is easy to understand and implement.







Also tagged with one or more of these keywords: routing, form_for helper

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users