# Beginners question regarding scaffold setup

**URL:** <https://www.ruby-forum.com/t/beginners-question-regarding-scaffold-setup/130741>\
**Category:** Rails\
**Created:** [March 2, 2008, 11:10pm UTC](https://www.ruby-forum.com/t/beginners-question-regarding-scaffold-setup/130741 "2008-03-02T23:10:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 2, 2008, 11:10pm UTC](https://www.ruby-forum.com/t/beginners-question-regarding-scaffold-setup/130741/1 "2008-03-02T23:10:53Z")

</div>

Hi, I’m trying to build my first rails app but I’m a little confused.  
From reading various bits of documentation, I was led to believe that  
the url the user types would mirror the controller/action setup. For  
example the url ‘message/hello’ would use the message/hello view and the  
‘hello’ action in the ‘message’ controller.

I have used a scaffold to create a user model and controller with the  
default values (new, edit, destroy etc). However, I have added a new  
view and action to the controller called ‘login’, but when I type in the  
url ‘users/login’, it tries to find a user whose id=‘login’.

How can I get around this? Thanks.

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 3, 2008, 12:34am UTC](https://www.ruby-forum.com/t/beginners-question-regarding-scaffold-setup/130741/2 "2008-03-03T00:34:31Z")

</div>

Dan S. wrote:

> I have used a scaffold to create a user model and controller with the  
> default values (new, edit, destroy etc). However, I have added a new  
> view and action to the controller called ‘login’, but when I type in the  
> url ‘users/login’, it tries to find a user whose id=‘login’.
> 
> How can I get around this? Thanks.

This suggests that you are using Rails 2.x and scaffolding has changed a  
little. Before version 2, the default was to generate routing for  
“controller/action” type URLs, but from version 2 the default is to  
generate RESTful URLs.

To see how URLs get mapped, run the following from your application top  
directory:

rake routes

You’ll see a line of the form:

user GET /users/:id {:controller=\>“users”, :action=\>“show”}

This is matched by the URL “/users/login” so this is why you are being  
sent to the “show” action and it is looking for a user with an id of  
“login”.

These REST URLs are produced by the following line in your  
config/routes.rb file:

map.resources :users

There are 2 things you can do. To get the style of URLs prior to  
version 2, comment out this line in the routes.rb file and restart the  
server. To keep RESTful routes, update the resources line to specify  
your new action. Actions that work on a specific ID are added with a  
:member argument, so:

map.resources :users, :member =\> { :my\_action =\> :get }

means that your application will now accept URLs of the form  
/users/:id/my\_action (the “rake routes” command will show this change to  
the routes). Alternatively, if the action doesn’t require a specific  
ID, then use the :collection argument:

map.resources :users, :collection =\> { :my\_action =\> :get }

This means you can access the URL /users/my\_action and reach your  
action. You can change :get to :post if the action must only apply to  
POST requests. Other possibilities are :put, :delete and :any. You can  
add both :member and :collection actions if you need to.

Have a look at #resources in the documentation:

[http://api.rubyonrails.com/classes/ActionController/Resources.html#M000308](http://api.rubyonrails.com/classes/ActionController/Resources.html#M000308)

Also search this forum for posts on routes and resources as there have  
been many posts on the topic. There are also many websites with  
information about the new scaffolding mechanisms.

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 3, 2008, 4:33am UTC](https://www.ruby-forum.com/t/beginners-question-regarding-scaffold-setup/130741/3 "2008-03-03T04:33:39Z")

</div>

On Mon, Mar 3, 2008 at 10:04 AM, Mark B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Other possibilities are :put, :delete and :any.

This may sound stupid of me, but I didn’t know of that :any option.

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [October 31, 2008, 5:48pm UTC](https://www.ruby-forum.com/t/beginners-question-regarding-scaffold-setup/130741/4 "2008-10-31T17:48:37Z")

</div>

Good blogs for Ruby On Rails Developers

> **[Ruby On Rails Development](http://rubyonrails4all.blogspot.com/)**
>
> Ruby On Rails from Novice to Professional

> **[Ruby On Rails Programming](http://rubyonrails-programming.blogspot.com/)**
>
> Ruby On Rails Tutorials, Code Snippets and Many More....

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [October 31, 2008, 5:48pm UTC](https://www.ruby-forum.com/t/beginners-question-regarding-scaffold-setup/130741/5 "2008-10-31T17:48:01Z")

</div>

Good blogs for Ruby On Rails Developers

> **[Ruby On Rails Development](http://rubyonrails4all.blogspot.com/)**
>
> Ruby On Rails from Novice to Professional

> **[Ruby On Rails Programming](http://rubyonrails-programming.blogspot.com/)**
>
> Ruby On Rails Tutorials, Code Snippets and Many More....
