Forum: Ruby on Rails routing to custom defined controller method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3cde62622689256e4573d31686b6ea89?d=identicon&s=25 Cesar (Guest)
on 2009-04-06 09:42
(Received via mailing list)
Hi, I'm developing my first rails project in Netbeans, with rails 2.1,
I used scaffold to generate my models, views and controllers.
The problem I'm having is that when I define a new method inside a
controller i can not access it using a "normal" url like /controller/
action
Instead, it can only be accessed by using a /controller/action/id kind
of url. If i use the /controler/action url it goes to the "show"
controller and throws an error.

Example: if I define this test1 method in users controllers It can
only be accesed by /users/test1/someid
instead of my desired /users/test1
class UsersController < ApplicationController

  def test1
    flash[:notice] = "Entre a login"
  end
  #here go all other scaffolded methods
end

I think it must have something to do with my routing, which is
configured like this...

ActionController::Routing::Routes.draw do |map|
  map.resources :users
  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

Please someone help me, thanks!
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-06 10:04
(Received via mailing list)
On Apr 5, 11:32 pm, Cesar <cesarepare...@gmail.com> wrote:
> Hi, I'm developing my first rails project in Netbeans, with rails 2.1,
> I used scaffold to generate my models, views and controllers.
> The problem I'm having is that when I define a new method inside a
> controller i can not access it using a "normal" url like /controller/
> action
> Instead, it can only be accessed by using a /controller/action/id kind
> of url. If i use the /controler/action url it goes to the "show"
> controller and throws an error.
>

Have a look at the :member and :collection options to map.resources
(or have a look at the routing guide
http://guides.rubyonrails.org/routing.html
)

Fred
This topic is locked and can not be replied to.