开发者

Rails 3.0 Routing Problem

So I've created a named route like follows:

match 'deactivate/:id' => 'events#deactivateEvent', :constraints => {:id => /\d+/}, :via => [:get, :post]

In my view I have this line of code:

 <%= link_to 'Deactivate', deactivate_path(@event.id) %>

Now I get the following error: NoMethodError in Events#show

Showing C:/Users/redbush/Desktop/ticket/app/views/events/show.html.erb w开发者_StackOverflowhere line #33 raised:

undefined method `deactivate_path' for #<#:0x817f050>

Extracted source (around line #33):

 30: <% end %>
 31: 
 32: <% if @event.approval && !@event.deactivated && @event.active && @event.sales_start < Time.now %>
 33:    <%= link_to 'Deactivate', deactivate_path(@event.id) %>
 34: <% end %>

So I am really confused on why this is not working.

Any ideas?


Since you're setting up a manual match path, you need to provide it with the named route you want to use, using the :as parameter:

match 'deactivate/:id' => 'events#deactivateEvent', 
      :constraints => {:id => /\d+/}, 
      :via => [:get, :post], 
      :as => :deactivate

(See 3.6 Naming Routes in the Rails Routing guide)


add:

:as => :deactivate

at the end of your route

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜