在我的应用程序中,我有几个资源范围为“admin”,如下所示(在 routes.rb 中):
scope 'admin', :as => 'admin' do
resources :events
end
因此,当我通过表单使用 #new 或 #update 方法时,我最终会收到 ActionController 异常说No route matches [PUT] "/admin/events"
.
rake routes
产生以下内容:
admin_events GET /admin/events(.:format) events#index
POST /admin/events(.:format) events#create
new_admin_event GET /admin/events/new(.:format) events#new
edit_admin_event GET /admin/events/:id/edit(.:format) events#edit
admin_event GET /admin/events/:id(.:format) events#show
PUT /admin/events/:id(.:format) events#update
DELETE /admin/events/:id(.:format) events#destroy
_表单代码:
<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>
<%= form_for @event, :html => { :class => 'form-horizontal' }, :url => url_for(:controller => 'events', :action => 'index') do |f| %>
<fieldset>
<div class="control-group">
<%= f.label :name, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :name %>
</div>
</div>
<div class="control-group">
<%= f.label :event_date, :class => 'control-label' %>
<div class="controls date-selects">
<%= f.datetime_select :event_date, :start_year => 2012 %>
</div>
</div>
<div class="control-group">
<%= f.label :publish_date, :class => 'control-label' %>
<div class="controls date-selects">
<%= f.datetime_select :publish_date, :start_year => 2012 %>
</div>
</div>
<div class="control-group">
<%= f.label :blurb, :class => 'control-label' %>
<div class="controls">
<%= f.text_area :blurb, :class => 'span6 wysi' %>
</div>
</div>
<div class="control-group">
<%= f.label :graphic, :class => 'control-label' %>
<div class="controls">
<%= f.file_field :graphic %>
</div>
</div>
<div class="control-group">
<%= f.label :tix_link, :class => 'control-label' %>
<div class="controls">
<%= f.url_field :tix_link %>
</div>
</div>
<div class="form-actions">
<%= f.submit 'Submit', :class => 'btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")), admin_events_path, :class => 'btn' %>
</div>
</fieldset>
<% end %>
我究竟做错了什么?