Why do I get No Route Error in Rails 3 even though I have defined a route?
This is the error:
ActionView::Template::Error (No route matches {:action=>"send_to_client", :controller=>"stages"}):
app/views/stages/_show.html.erb:13:in `_app_views_stages__show_html_erb__3606907191157577988_2203521120_617355097038007272'
app/controllers/stages_controller.rb:78:in `block (2 levels) in create'
app/controllers/stages_controller.rb:75:in `create'
This is line 13 in the _show.html.erb
:
<%= link_to "<span class='icon send-to-client-icon' title='Send to Client'> </span>".html_safe, send_to_client_stage_path, :id => stage.id, :confirm => "This will send #{stage.name.capitalize} to #{stage.client.email}. Are you sure you are ready?" %>
This is my stages controller
, create
action:
def create
@stage = current_user.stages.create(params[:stage])
client = @stage.client
unless @stage.new_record?
respond_with(@stage, :status => :created, :location => @stage) do |format|
flash.now[:notice] = 'Stage was successfully created.'
format.html { redirect_to(@stage) }
format.js { render :partial => "stages/show", :locals => {:stage => @stage, :client => client}, :layout => false, :status => :created }
end
else
respond_with(@stage.errors, :status => :unprocessable_entity) do |format|
format.js { render :json => @stage.errors, :layout => false, :status => :unprocessable_entity }
format.html { render :action => "new" }
end
end
en开发者_StackOverflow社区d
Stages Controller
, send_to_client
action:
def send_to_client
stage = Stage.find(params[:id])
ClientMailer.send_stage(stage).deliver
if ClientMailer.send_stage(stage).deliver
flash[:notice] = "Successfully sent to client."
redirect_to("/")
else
flash[:notice] = "There were problems, please try re-sending."
redirect_to("/")
end
end
You are missing the ID and need to pass the stage
instance it in your send_to_client_stage_path
call.
send_to_client_stage_path(stage)
instead of:
send_to_client_stage_path
精彩评论