Reputation: 287540
In Ruby on Rails, is it possible to change a default action for a RESTful resource, so than when someone, for example, goes to /books it gets :new instead of the listing (I don't care if that means not being able to show the listing anymore)?
Upvotes: 2
Views: 1204
Reputation: 107728
def index
redirect_to new_book_path
end
I think would be the simplest way.
Upvotes: 0
Reputation: 15596
Not sure why would you do such a thing, but just add this
map.connect "/books", :controller => "books", :action => "new", :conditions => { :method => :get}
to your config/routes.rb before the
map.resources :books
and it should work.
Upvotes: 3
Reputation: 7297
I'd point out that if you are pointing /books to /books/new, you are going to be confusing anyone who is expecting REST. If you aren't working alone, or if you are and have other come on board later, or if you expect to expose an API to the outside, the REST convention is that /books takes you to a listing, /books/new is where you create a new record.
Upvotes: 3
Reputation: 6622
Yes. You should be able to replace your index method in your controller...
def index
@resource = Resource.new
# have your index template with they proper form
end
Upvotes: 0