I am a newbie to ruby/rails. I almost don''t know anything about rails, however, I am familiar with MVC3 of ASP.Net. Please help me with this question as I am about to fail a course. :( In my routes.rb file I have a nested resource: root to: "parentitems#index" resources :parentitemsdo resources :childitems, only: [:new, :create, :destroy] end In my parentitems\show\.html.erb file, I am adding a link and I don''t know how to do that. Which one of these would do the job, if any? <%= link_to ''New Childitem'', new_parentitem_childitem_url %> <%= link_to ''New Childitem'', new_parentitem_childitem_path %> and what do I need to specify in the routes.rb file so that this link goes to the new view for childitems? Thanks you for the hlep. -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
dis guy wrote in post #1088348:> I am a newbie to ruby/rails. I almost don''t know anything about rails, > however, I am familiar with MVC3 of ASP.Net. Please help me with this > question as I am about to fail a course. :( > > In my routes.rb file I have a nested resource: > > root to: "parentitems#index" > resources :parentitemsdo > resources :childitems, only: [:new, :create, :destroy] > end > > In my parentitems\show\.html.erb file, I am adding a link and I don''t > know how to do that. > > Which one of these would do the job, if any? > > <%= link_to ''New Childitem'', new_parentitem_childitem_url %> > <%= link_to ''New Childitem'', new_parentitem_childitem_path %> > > and what do I need to specify in the routes.rb file so that this link > goes to the new view for childitems? > > Thanks you for the hlep.If you go with command line to the root of your project and run "rake routes" (remove quotation marks ) you will see the routes your application has and how to use them to access the methods you implement. Please run that and post it here in case you cannot find the right one to use. Cheers. -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
This is what I see: new_parentitem_childitem GET /parentitems/:parentitem_id/childitems/new(.:format) childitems#new But this in my routes file doesn''t work: match ''/parentitems/:parentitem_id/childitems/new'' => ''childitems#new'' -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
And I am not sure about my controller either: def new @childitem= Childitem.new respond_to do |format| format.html # new.html.erb format.json { render json: @childitem} end end -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
dis guy wrote in post #1088404:> This is what I see: > > new_parentitem_childitem GET > /parentitems/:parentitem_id/childitems/new(.:format) childitems#new > > > > But this in my routes file doesn''t work: > > match ''/parentitems/:parentitem_id/childitems/new'' => ''childitems#new''Why are you now defining the routes using match? Before you were using: resources :parentitemsdo resources :childitems, only: [:new, :create, :destroy] end For that new_parentitem_childitem_path should work for a link_to Notice that resources :parentitemsdo should be resources :parentitems do (I guess a space was missing before the do...) ----- With the match way what does it mean it doesn''t work anyway, what error do you get? Have you reviewed this guide? http://guides.rubyonrails.org/routing.html -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
I want to add a Link_to now to add a create new item page for child item and I am using the match for that page. <%= link_to ''New Childitem'', new_parentitem_childitem_path %> No, the space exists in my routes file, was a type here. The error message is: Routing Error No route matches {:action=>"new", :controller=>"childitems"} Try running rake routes for more information on available routes. -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.