Quick questions about link_to

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?

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.

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 (http://www.manning.com/black)
(See what readers are saying! 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)

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’ %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs