这是错误:
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'
这是_show.html.erb
中的第13行:
<%= 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?" %>
这是我的stages controller
,create
操作:
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
end
Stages Controller
,send_to_client
行动:
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
答案 0 :(得分:4)
您错过了ID,需要在stage
来电中传递send_to_client_stage_path
个实例。
send_to_client_stage_path(stage)
而不是:
send_to_client_stage_path