[Rails] Re: Question about link_to

2011-08-07 Thread Pepe Sanchez
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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Question about link_to

2011-08-07 Thread Colin Law
On 7 August 2011 15:31, Pepe Sanchez li...@ruby-forum.com 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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Question about link_to

2011-08-07 Thread 7stud --
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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Question about link_to

2011-08-06 Thread Pepe Sanchez
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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Question about link_to

2011-08-06 Thread Walter Lee Davis


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- 
t...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com 
.
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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.