views:

161

answers:

3

using Ruby on Rails 2.3.2, since I already created Scaffold for Story, so instead of experimenting and creating a new action called "new" ("new" already exists from the scaffold), i used "newnew" in the controller file and in the view file, hoping that

http://localhost:3000/stories/newnew

will be another way to create a new record. but turns out RoR will treat "newnew" as a record id instead of an action, as it is reported:

Couldn't find Story with ID=newnew

is there a way to make newnew also as an action?

route.rb has

map.resources :stories

map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

and it is Rails 2.3.2

A: 

The default action is to list something with a URL like that. You can implement newnew in your stories controller, but why?

Rob Elsner
+2  A: 

The source of the issue is likely to be in your routes.rb, can you post its content into your question?

Depending on the version of rails and whether you are using RESTful resources, the behaviour differs. Either way, the routes.rb should hold the answer.

fd
please read update
動靜能量
The "map.resources :stories" is what is giving this behaviour. This makes your stories controller RESTful, which defines 7 actions (new, create, edit, update, show, delete and index). Anything that is not one of those actions on that controller is assumed to be the show action, and the URL segment is assumed to be the id of the record to show.
fd
Ryan Bates has some nice rails screencasts you can look at in all areas of rails. Here some about ActiveResource that you might find interesting: http://railscasts.com/tags/19. And here some about routing: http://railscasts.com/tags/14
fd
+2  A: 
map.resources :stories, :collection => {:newnew => :get}

... will add the newnew mapping to the stories collection. This will know that /stories/newnew isn't meant to refer to an instance of stories.

From here.

wombleton