I made a button using "<%= button_to "New", :action => "click" %>" and have a method in controller as: def click end In router file i had added resources as " resources: posts" .In app/view/posts/click.html.erb file holds simple hello message,but when i click on the button it says: No route matches {:controller=>"posts", :action=>"click"}. John -- 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 26 May 2011 13:31, John <johnsshelfer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I made a button using "<%= button_to "New", :action => "click" %>" and have > a method in controller as: > def click > end > In router file i had added resources as " resources: > posts" .In app/view/posts/click.html.erb file holds simple hello message,but > when i click on the button it says: > > No route matches {:controller=>"posts", > :action=>"click"}.resources: posts just gives you the standard routes. If you want a non-standard one you have to add it yourself. See the Rails Guide on Routing for more information. You can type rake routes to find what routes are defined. If you do that you will find that posts/click is not there at the moment, so you get the error. 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Click isn''t one of the REST states, so you will have to add that to your routes. In Rails 2.3, this looks like this: map.resources :posts, :member => { :click => :get } In Rails 3, you would do: resources :posts do member do get ''click'' end end Walter On May 26, 2011, at 8:31 AM, John wrote:> I made a button using "<%= button_to "New", :action => "click" %>" > and have a method in controller as: > def click > end > In router file i had added resources as " > resources: posts" .In app/view/posts/click.html.erb file holds > simple hello message,but when i click on the button it says: > > > No route matches > {:controller=>"posts", :action=>"click"}. > > John > > -- > 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.
On 26 May 2011 13:40, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 May 2011 13:31, John <johnsshelfer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> I made a button using "<%= button_to "New", :action => "click" %>" and have >> a method in controller as: >> def click >> end >> In router file i had added resources as " resources: >> posts" .In app/view/posts/click.html.erb file holds simple hello message,but >> when i click on the button it says: >> >> No route matches {:controller=>"posts", >> :action=>"click"}. > > resources: posts just gives you the standard routes. If you want a > non-standard one you have to add it yourself. See the Rails Guide on > Routing for more information. > You can type > rake routes > to find what routes are defined. If you do that you will find that > posts/click is not there at the moment, so you get the error.I have just realised that the OP here is John Shelfer who has already been advised to study that guide in order to understand routing. John, assuming that you did study that guide, please ask for clarification of which bits you did not understand. It will be better to get a good understanding rather than just have those here help you out each time you have a trivial problem. 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 May 2011 13:46, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I have just realised that the OP here is John ShelferThe beauty of email filters.... -- 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 Thu, May 26, 2011 at 8:43 AM, Walter Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Click isn''t one of the REST states, so you will have to add that to your > routes. In Rails 2.3, this looks like this: > > map.resources :posts, :member => { :click => :get } > > In Rails 3, you would do: > > resources :posts do > member do > get ''click'' > end > endI have rails 3.0.7.Added a route as above but still line "<%button_to "New", :action => "click" %>" generate the error . "No route matches {:controller=>"posts", :action=>"click"}" John -- 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 26 May 2011 14:13, John <johnsshelfer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Thu, May 26, 2011 at 8:43 AM, Walter Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: >> >> Click isn''t one of the REST states, so you will have to add that to your >> routes. In Rails 2.3, this looks like this: >> >> map.resources :posts, :member => { :click => :get } >> >> In Rails 3, you would do: >> >> resources :posts do >> member do >> get ''click'' >> end >> end > > I have rails 3.0.7.Added a route as above but still line "<%> button_to "New", :action => "click" %>" generate the error . > "No route matches {:controller=>"posts", :action=>"click"}"That is the result of following advice without understanding that advice. The above syntax is explained in section 2.9.1 of the rails guide on routing and expects an id to be passed, which is not what you want. As has been stated several times you can use rake routes to see what routes you have declared, and you will see that posts/click is not one of them. If you just want a static route (which I think you do) then have a look at section 3.3 This time make sure that rake routes shows the result you expect. If you still cannot get it to work post what you have tried and what you see in rake routes. 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, May 26, 2011 at 9:27 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 May 2011 14:13, John <johnsshelfer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On Thu, May 26, 2011 at 8:43 AM, Walter Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> > wrote: > >> > >> Click isn''t one of the REST states, so you will have to add that to your > >> routes. In Rails 2.3, this looks like this: > >> > >> map.resources :posts, :member => { :click => :get } > >> > >> In Rails 3, you would do: > >> > >> resources :posts do > >> member do > >> get ''click'' > >> end > >> end > > > > I have rails 3.0.7.Added a route as above but still line "<%> > button_to "New", :action => "click" %>" generate the error . > > "No route matches {:controller=>"posts", :action=>"click"}" > > That is the result of following advice without understanding that > advice. The above syntax is explained in section 2.9.1 of the rails > guide on routing and expects an id to be passed, which is not what you > want. > > As has been stated several times you can use rake routes to see what > routes you have declared, and you will see that posts/click is not one > of them. >rake routes gave and following and it seems posts/click is there. posts_index GET /posts/index(.:format) {:action=>"index", :controller=>"posts"} click_post GET /posts/:id/click(.:format) {:action=>"click", :controller=>"posts"} posts GET /posts(.:format) {:action=>"index", :controller=>"posts"} POST /posts(.:format) {:action=>"create", :controller=>"posts"} new_post GET /posts/new(.:format) {:action=>"new", :controller=>"posts"} edit_post GET /posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"} post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"} PUT /posts/:id(.:format) {:action=>"update", :controller=>"posts"} DELETE /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"}> > If you just want a static route (which I think you do) then have a > look at section 3.3 >match '':posts/:click'' didn''t work as per tutorial there.> > This time make sure that rake routes shows the result you expect. If > you still cannot get it to work post what you have tried and what you > see in rake routes. > I just want a simple button at click which will show the Hello message in > /app/views/posts/click.html.erbJohn -- 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 26 May 2011 17:06, John <johnsshelfer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Thu, May 26, 2011 at 9:27 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 26 May 2011 14:13, John <johnsshelfer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > >> > On Thu, May 26, 2011 at 8:43 AM, Walter Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> >> > wrote: >> >> >> >> Click isn''t one of the REST states, so you will have to add that to >> >> your >> >> routes. In Rails 2.3, this looks like this: >> >> >> >> map.resources :posts, :member => { :click => :get } >> >> >> >> In Rails 3, you would do: >> >> >> >> resources :posts do >> >> member do >> >> get ''click'' >> >> end >> >> end >> > >> > I have rails 3.0.7.Added a route as above but still line "<%>> > button_to "New", :action => "click" %>" generate the error . >> > "No route matches {:controller=>"posts", :action=>"click"}" >> >> That is the result of following advice without understanding that >> advice. The above syntax is explained in section 2.9.1 of the rails >> guide on routing and expects an id to be passed, which is not what you >> want. >> >> As has been stated several times you can use rake routes to see what >> routes you have declared, and you will see that posts/click is not one >> of them. > > rake routes gave and following and it seems posts/click is there. > posts_index GET /posts/index(.:format) {:action=>"index", > :controller=>"posts"} > click_post GET /posts/:id/click(.:format) {:action=>"click", > :controller=>"posts"}Note that it has an id in there, as I said.> posts GET /posts(.:format) {:action=>"index", > :controller=>"posts"} > POST /posts(.:format) {:action=>"create", > :controller=>"posts"} > new_post GET /posts/new(.:format) {:action=>"new", > :controller=>"posts"} > edit_post GET /posts/:id/edit(.:format) {:action=>"edit", > :controller=>"posts"} > post GET /posts/:id(.:format) {:action=>"show", > :controller=>"posts"} > PUT /posts/:id(.:format) {:action=>"update", > :controller=>"posts"} > DELETE /posts/:id(.:format) {:action=>"destroy", > :controller=>"posts"} > >> >> If you just want a static route (which I think you do) then have a >> look at section 3.3 > > match '':posts/:click'' didn''t work as per tutorial there.Once again you have taken advice (in this case mine) without understanding what is being suggested. I should have directed you to section 3.7. If you had read and understood the guide you would have seen this and not been led astray by my bad advice. 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
After reading routing tutorial ,made some changes.Button is created using "<%= button_to "New", :action => "click" %>" .When i clicked the button error is: No routes matches "/posts/click" In router.rb ,i added a route to click action of controller as but error is not resolved yet. Check::Application.routes.draw do get "posts/index" resources :posts do end get ''posts/click'' # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match ''products/:id'' => ''catalog#view'' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # match ''products/:id/purchase'' => ''catalog#purchase'', :as => :purchase # This route can be invoked with purchase_url(:id => product.id) # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products # Sample resource rwith_user/:uoute with options: # resources :products do # member do # get ''short'' # post ''toggle'' # end # # collection do # get ''sold'' # end # end # Sample resource route with sub-resources: # resources :products do # resources :comments, :sales # resource :seller # end # Sample resource rwith_user/:uoute with more complex sub-resources # resources :products do # resources :comments # resources :sales do # get ''recent'', :on => :collection # end # end # Sample resource route within a namespace: # namespace :admin do # # Directs /admin/products/* to Admin::ProductsController # # (app/controllers/admin/products_controller.rb) # resources :products # end # You can have the root of your site routed with "root" # just remember to delete public/index.html. # root :to => "welcome#index" # See how all your routes lay out with "rake routes" # This is a legacy wild controller route that''s not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. # match '':controller(/:action(/:id(.:format)))'' end John -- 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.
map.root :controller => "controller_name", :action => "Index" map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' Did you try this? -- 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.
ActionController::Routing::Routes.draw do |map| map.root :controller => "controller_name", :action => "Index" map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' end Did you try this code? -- 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 27 May 2011 09:43, John <johnsshelfer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > After reading routing tutorial ,made some changes.Button is created using > "<%= button_to "New", :action => "click" %>" .When i clicked the button > error is: > No routes matches "/posts/click" > > In router.rb ,i added a route to click action of controller as but error is > not resolved yet. > Check::Application.routes.draw do > get "posts/index" > resources :posts do > > end > get ''posts/click''Once again I have to ask whether the route appears when you do rake routes Your first action should be to do that and make sure the route appears there. If it does not then experiment with routes.rb until it does appear in rake routes. Did you remember to restart the server after editing routes.rb? 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, May 27, 2011 at 5:59 AM, Bala TS <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> ActionController::Routing::Routes.draw do |map| > > map.root :controller => "controller_name", :action => "Index" > map.connect '':controller/:action/:id'' > map.connect '':controller/:action/:id.:format'' > > end > it worked.Thank you.I am newbiee to rails,so please can you explain above > code a bit.John -- 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.