Friday, August 12, 2011

[Rails] routes question

Why does this link:

<h1>Pages#home</h1>
<p>Find me in app/views/pages/home.html.erb</p>

<%= link_to "Update clicks ", { :controller => 'users', :action =>
'update_clicks'} %>


...route me to the users/show page? Here are my routes:


Test2App::Application.routes.draw do
resources :users
root :to => "pages#home"

post 'users/update_clicks'


I know I can get the link to go to 'pages/home' as intended by adding
:method => post to the link, but I'm curious how the the users/show page
gets rendered? I would expect a 'get' request to 'users/update_clicks'
to produce a routing error.


Here are my controllers:

class PagesController < ApplicationController
def home
@title = "Home"
end
end


class UsersController < ApplicationController
def update_clicks
render 'pages/home'
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate