No route matches "/userhome/18/edit_reviewer_email"
The test line that i set up in the controller is not printing in the console... so the action is going back to edit_reviewer_email without following the defined route. Here is the code.
edit_reviewer_email:
<%= form_for :user, @user, update_reviewer_email_userhome_path do |f| %>
<%= f.text_field :email %>
<%= f.submit "Update Email" %>
<% end %>
warning:
DEPRECATION WARNING: Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead.
userhome_controller:
def update_reviewer_email
p "***" # test line
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to(root_path, :notice => 'Email was successfully updated.') }
format.xml { head 开发者_JAVA技巧:ok }
else
format.html { render :action => "edit_reviewer_email" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
error:
No route matches "/userhome/18/edit_reviewer_email"
route:
resources :userhome, :except => [:show, :new, :edit, :update, :destroy] do
member do
get :edit_reviewer_email
post :update_reviewer_email
end
end
rake routes:
update_reviewer_email_userhome POST /userhome/:id/update_reviewer_email(.:format) {:action=>"update_reviewer_email", :controller=>"userhome"}
log file:
Started POST "/userhome/18/edit_reviewer_email" for 127.0.0.1 at 2011-07-15 09:36:52 -0400
ActionController::RoutingError (No route matches "/userhome/18/edit_reviewer_email"):
Rendered /Users/me/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.7ms)
Thanks for your help.
Ok so you have
<%= form_for :user, @user, update_reviewer_email_userhome_path do |f| %>
which should do a POST request to /userhome/18/update_reviewer_email
however in log you have
Started POST "/userhome/18/edit_reviewer_email"
that obviously doesn't match any of your routes to fix it please try change your form to
<%= form_for :user, @user, :url => update_reviewer_email_userhome_path do |f| %>
精彩评论