Hi all I am working on the first application from the book "Head First Rails" called "tickets". What I do not understand is where the variable "new_ticket_path" gets populated in the view index.html.erb <%= link_to ''New Ticket'', new_ticket_path %> Please advise -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 6, 2011, at 12:46 PM, Pepe Sanchez wrote:> Hi all > > I am working on the first application from the book "Head First > Rails" > called "tickets". What I do not understand is where the variable > "new_ticket_path" gets populated in the view index.html.erb > > > <%= link_to ''New Ticket'', new_ticket_path %> > > Please advise >This path is made up by the rails router. If you have ''resources :tickets'' in your routes file, then this path is generated automatically for you. Type rake routes in your Terminal to see the whole lot of them. There''s an excellent Rails Guide about this, called Routing from the Outside In. Walter -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter, So if I understand correctly new_ticket_path, edit_ticket_path, ticket are like constants that RoR assigns to them specific values. If I want to create a new link on my RoR Application to a new page called for example "myblog", and add it to the index page, which will be the right syntax? link_to "myblog", ?????? Thanks jose -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 6, 2011, at 1:22 PM, Pepe Sanchez wrote:> Walter, > > So if I understand correctly new_ticket_path, edit_ticket_path, ticket > are like constants that RoR assigns to them specific values. > > If I want to create a new link on my RoR Application to a new page > called for example "myblog", and add it to the index page, which > will be > the right syntax? > > link_to "myblog", ??????That depends on where the blog is coming from. If it is part of your Rails application, and you are linking to it from a different part of the same Rails application, then you might be able to do something like: link_to "My Blog", posts_path Which would generate a link like this: <a href="http://localhost:3000/posts ">My Blog</a> That''s assuming that your blog is rendered by the #index method of the PostsController. Substitute your own controller name as needed. If you have two separate Rails applications, and you want to link from one to the other, then you can either use a hand-written link, or you can use the :url attribute in the link_to method. Read up on the link_to generator in the API docs: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to Walter> > Thanks > jose > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I understand now! To generate a link in my RoR application I just need to prefix the word "_path" with a controller name and it finds it. Thanks -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 August 2011 15:31, Pepe Sanchez <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I understand now! > > To generate a link in my RoR application I just need to prefix the word > "_path" with a controller name and it finds it.That is only part of it. Did you read the Rails Guide on routing, as Walter suggested. This is absolutely required reading (and understanding). Colin -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Pepe Sanchez wrote in post #1015368:>First of all, I think this: <%= link_to ''New Ticket'', new_ticket_path %> should say: new_tickets_path. Note the plural form of tickets. At least that is the way it is in Rails 3.09. Head First Rails is an old enough book that it''s probably not worth studying. 2008??! That''s a lifetime ago in computer programming, and rails changes faster than most things in the programming world.> I understand now! > > To generate a link in my RoR application I just need to prefix the word > "_path" with a controller name and it finds it. >That''s not necessarily true. You were on the right track to begin with. The second argument to the link_to method can be a path. Rails will create some paths for you and assigns names to them, like new_tickets_path, which you can use as the second argument to link_to. Rails also automatically creates some methods you can use: new_ticket_path(@ticket) which creates the path to a page that shows a particular ticket. But if one of those ''constants'' or methods actually produces the path: ''/some_page'' You could just specify that path directly yourself: <%= link_to ''New Ticket'', ''/somepage'' %> As long as your routes file maps the path you specify as the second argument to link_to to one of your actions, it will work. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.