为什么即使我已经定义了路由,Rails 3中也没有路由错误?

时间:2011-04-15 15:35:51

标签: ruby-on-rails ruby-on-rails-3

这是错误:

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 controllercreate操作:

  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 Controllersend_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

1 个答案:

答案 0 :(得分:4)

您错过了ID,需要在stage来电中传递send_to_client_stage_path个实例。

send_to_client_stage_path(stage)

而不是:

send_to_client_stage_path