如何创建感谢页面?

时间:2013-01-24 20:35:27

标签: ruby-on-rails-3

我正在尝试创建一个感谢页面,我的路由工作正常,因为我测试它的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

2 个答案:

答案 0 :(得分:1)

您需要add it as a RESTful action(或采用默认匹配路线)。

果壳:

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

或者:

resources :appointments do
  get 'thank_you', :on => :member
end

答案 1 :(得分:0)

要获得新页面,您必须做的不仅仅是编辑控制器。

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

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