# Quick questions about link\_to

**URL:** <https://www.ruby-forum.com/t/quick-questions-about-link-to/81888>\
**Category:** Rails\
**Created:** [January 16, 2007, 2:16am UTC](https://www.ruby-forum.com/t/quick-questions-about-link-to/81888 "2007-01-16T02:16:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![figo2476](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@figo2476](https://www.ruby-forum.com/u/figo2476)\
**Post date:** [January 16, 2007, 2:16am UTC](https://www.ruby-forum.com/t/quick-questions-about-link-to/81888/1 "2007-01-16T02:16:08Z")

</div>

e.g.

index.rhtml has:  
\<%= link\_to ‘nextpage’ :action=\>‘show’ %\>  
when it is clicked, it will take you to nextpage\_controller, then  
execute ‘show’, then stay in nextpage.rhtml.

If that is the case, action ‘show’ has to exist, even it is an empty  
action, in order to take you from index.rhtml to nextpage.rhtml, right?

---

<div class="post-metadata">

**Author:** ![figo2476](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@figo2476](https://www.ruby-forum.com/u/figo2476)\
**Post date:** [January 16, 2007, 4:27am UTC](https://www.ruby-forum.com/t/quick-questions-about-link-to/81888/2 "2007-01-16T04:27:28Z")

</div>

Gary Liang wrote:

> e.g.
> 
> index.rhtml has:  
> \<%= link\_to ‘nextpage’ :action=\>‘show’ %\>  
> when it is clicked, it will take you to nextpage\_controller, then  
> execute ‘show’, then stay in nextpage.rhtml.
> 
> If that is the case, action ‘show’ has to exist, even it is an empty  
> action, in order to take you from index.rhtml to nextpage.rhtml, right?

I make this question simplier.

Does it mean nextpage.rhtml must has a controller & action ‘show’, in  
order to transfer to from index.rhtml (index.rhtml has \<%= link\_to  
‘nextpage’ :action=\>‘show’ %\> ?) to nextpage.rhtml.

---

<div class="post-metadata">

**Author:** ![figo2476](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@figo2476](https://www.ruby-forum.com/u/figo2476)\
**Post date:** [January 16, 2007, 4:40am UTC](https://www.ruby-forum.com/t/quick-questions-about-link-to/81888/3 "2007-01-16T04:40:03Z")

</div>

Hi –

On Tue, 16 Jan 2007, Gary Liang wrote:

> > action, in order to take you from index.rhtml to nextpage.rhtml, right?
> 
> I make this question simplier.
> 
> Does it mean nextpage.rhtml must has a controller & action ‘show’, in order  
> to transfer to from index.rhtml (index.rhtml has \<%= link\_to ‘nextpage’  
> :action=\>‘show’ %\> ?) to nextpage.rhtml.

You can have no show action, in which case it will be treated as just  
a request to render show.rhtml. I usually like to put:

def show  
end

in my controller anyway, just to denote the fact that I’m expecting  
requests to it.

David

–  
Q. What is THE Ruby book for Rails developers?  
A. RUBY FOR RAILS by David A. Black ([Ruby for Rails](http://www.manning.com/black))  
(See what readers are saying! [http://www.rubypal.com/r4rrevs.pdf](http://www.rubypal.com/r4rrevs.pdf))  
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?  
A. Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![figo2476](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@figo2476](https://www.ruby-forum.com/u/figo2476)\
**Post date:** [January 16, 2007, 6:49am UTC](https://www.ruby-forum.com/t/quick-questions-about-link-to/81888/4 "2007-01-16T06:49:37Z")

</div>

> Does it mean nextpage.rhtml must has a controller & action ‘show’, in  
> order to transfer to from index.rhtml (index.rhtml has \<%= link\_to  
> ‘nextpage’ :action=\>‘show’ %\> ?) to nextpage.rhtml.

This link won’t change controllers because you haven’t specified a  
“:controller” option. This link will simply point to the “show” action  
in the same controller as index.rhtml. That means that rails will try to  
render a view named show.rhtml in the same directory as index.rhtml.

If you want to go to the nextpage.rhtml view (nextpage action) in the  
current controller, then you need to use a link like this:

\<%= link\_to ‘Next Page’ :action=\>‘nextpage’ %\>

Note that the first string is what the user sees in the link. If you  
want to go to the show.rhtml view in the nextpage controller (for  
example), then you need a link like this:

\<%= link\_to ‘Next Page’ :controller =\> ‘nextpage’, :action=\>‘show’ %\>
