Question : Creating a New View -  ActiveRecord::RecordNotFou<wbr />nd in CardsController#show

I'm just trying to create a new view.

I have cards controller, with the standard add/edit/delete pages.

I wanted to add a link in cards/index.html.erb to link to "Request New Card" which will be request_new.

request_new.html.erb is in the cards directory.

When I click on the link from http://localhost:3000/cards, the link being:
<%= link_to "here", :action => "request_new"%>
 It thinks the request_new is an id of a card to SHOW.  I get the following error page:

 ActiveRecord::RecordNotFound in CardsController#show

Couldn't find Card with ID=request_new

RAILS_ROOT: /home/xxxxx/xxxxx
Application Trace | Framework Trace | Full Trace

/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1379:in `find_one'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1362:in `find_from_ids'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:537:in `find'
app/controllers/cards_controller.rb:17:in `show'

What am I missing?

I tried adding
def request_new
end

to the cardscontroller.  But the same thing happens.

Answer : Creating a New View -  ActiveRecord::RecordNotFou<wbr />nd in CardsController#show

That's probably the more correct way, actually.  If you're creating a new card, you should use the 'new' and 'create' actions and define them the way you want.

If you want to add other actions, though, you have to add extra actions into the routing so it knows what HTTP verb they use.

First, read the API:
http://api.rubyonrails.com/classes/ActionController/Resources.html#M000696

Specifically, you're interested in the options that you can pass to resources.

Yours will probably be something like this.
1:
map.resources :cards, :new => {:request_new => :any}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us