-1

我正在尝试创建一个感谢页面,我的路线运行良好,因为我测试了它的 url 并且运行良好,但是当我尝试在创建操作中重定向时,我得到:

Routing Error

No route matches {:action=>"thank_you", :locale=>:en, :controller=>"appointments"}

控制器

  def create
    @appointment = Appointment.new(params[:appointment])

      if @appointment.save
        #send email
        AppointmentMailer.appointment_confirmation(@appointment).deliver
        AppointmentMailer.new_appointment(@appointment).deliver
        redirect_to :action => "thank_you"
      else
        render :action => 'new', :alert => @appointment.errors.full_messages.split(', ')
      end
  end


  def thank_you
      @appointment = Appointment.find(params[:id])
  end

路线

resources :appointments, :except => :new do
      member do
        get :thank_you
      end
    end
4

2 回答 2

1

您需要将其添加为 RESTful 操作(或假定默认匹配路由)。

简而言之:

resources :appointments do
  member do
    get 'thank_you'
  end
end

或者:

resources :appointments do
  get 'thank_you', :on => :member
end
于 2013-01-24T20:39:23.580 回答
0

要获得一个新页面,您需要做的不仅仅是编辑控制器。

  1. 编辑 config/routes.rb 并包含

    match "/appointments/thank_you" => "appointments#thank_you"
    
  2. 您可能想render在控制器中插入命令,这会给您带来一个感谢您必须创建的视图...

于 2013-01-24T20:40:40.567 回答