I have a route like this: map.resources :blog, :controller => ''posts'' This seems to confuse form_for''s model introspection when using this syntax: form_for @post do |f| ... end When I go to a page that has that code, I get a NoMethodError: undefined method `posts_path'' for #<ActionView::Base:0x103dd2030> I''ve discovered I can fix it by doing: form_for @post, :url => { :action = ''whatever-action-it-should-have- been'' } do |f| ... end Do I need to manually set the :url parameter like this every time I use form_for or is there a way to get it to globally recognize my altered named routes? Thanks in advance!
I actually used :as before using :controller, and while it recognized routes using the "aliased" name, the URL helpers generated links using the "real" name. Perhaps I was using the wrong helpers, though. I will look into it again. Thanks for your response! On Sep 9, 3:03 am, Abhinav Saxena <abhinav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> As far as I understand, you are trying to generate URLs with resource > name "blog" when actual controller is named posts. So the correct path > should be blogs_path (for your example) and not posts_path, and I > think it''s a good idea that you specify it always. I don''t know if you > can specify it globally. > > But if it suits your need you can use :as. From rails guide:http://guides.rubyonrails.org/routing.html > map.resources :photos, :as => "images" > will recognize incoming URLs containing image but route the requests > to the Photos controller > > Thanks, > Abhinav > -- > अभिनवhttp://twitter.com/abhinav > > > > On Wed, Sep 9, 2009 at 4:25 AM, Perceptes <jimmycua...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a route like this: > > > map.resources :blog, :controller => ''posts'' > > > This seems to confuse form_for''s model introspection when using this > > syntax: > > > form_for @post do |f| ... end > > > When I go to a page that has that code, I get a NoMethodError: > > > undefined method `posts_path'' for #<ActionView::Base:0x103dd2030> > > > I''ve discovered I can fix it by doing: > > > form_for @post, :url => { :action = ''whatever-action-it-should-have- > > been'' } do |f| ... end > > > Do I need to manually set the :url parameter like this every time I > > use form_for or is there a way to get it to globally recognize my > > altered named routes? > > > Thanks in advance!
Trying it again, using :on did what I was expecting. I think I most have mistakenly tried used alias_path instead of original_path when I was trying it the first time. Case closed! Thanks again! On Sep 9, 12:11 pm, Perceptes <jimmycua...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I actually used :as before using :controller, and while it recognized > routes using the "aliased" name, the URL helpers generated links using > the "real" name. Perhaps I was using the wrong helpers, though. I will > look into it again. Thanks for your response! > > On Sep 9, 3:03 am, Abhinav Saxena <abhinav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > As far as I understand, you are trying to generate URLs with resource > > name "blog" when actual controller is named posts. So the correct path > > should be blogs_path (for your example) and not posts_path, and I > > think it''s a good idea that you specify it always. I don''t know if you > > can specify it globally. > > > But if it suits your need you can use :as. From rails guide:http://guides.rubyonrails.org/routing.html > > map.resources :photos, :as => "images" > > will recognize incoming URLs containing image but route the requests > > to the Photos controller > > > Thanks, > > Abhinav > > -- > > अभिनवhttp://twitter.com/abhinav > > > On Wed, Sep 9, 2009 at 4:25 AM, Perceptes <jimmycua...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have a route like this: > > > > map.resources :blog, :controller => ''posts'' > > > > This seems to confuse form_for''s model introspection when using this > > > syntax: > > > > form_for @post do |f| ... end > > > > When I go to a page that has that code, I get a NoMethodError: > > > > undefined method `posts_path'' for #<ActionView::Base:0x103dd2030> > > > > I''ve discovered I can fix it by doing: > > > > form_for @post, :url => { :action = ''whatever-action-it-should-have- > > > been'' } do |f| ... end > > > > Do I need to manually set the :url parameter like this every time I > > > use form_for or is there a way to get it to globally recognize my > > > altered named routes? > > > > Thanks in advance!