2013-01-24 76 views
-2

我試圖創建一個感謝您網頁,我的這條路線,因爲我測試的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 

回答

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 
+0

我做了,我已經將路線代碼添加到pos,並且仍然出現錯誤。 – evanx

+0

@evanx您是否重新啓動? –

+0

是的。沒有路線匹配{:action =>「show」,:controller =>「schedules」,:locale =>:en,**:id => nil **}。 @DaveNewton – evanx

0

爲了得到一個新的頁面,你所要做的不僅僅是編輯控制器的更多。

  1. 編輯的config/routes.rb中,包括

    match "/appointments/thank_you" => "appointments#thank_you" 
    
  2. 您可能要插入控制器render命令,將您帶到您查看您必須創建一個感謝...

+0

IMO如果它是一個標準的資源,使用現有的'資源'路線更清潔。此外,最近的Rails版本會執行[默認,基於約定的渲染](http://guides.rubyonrails.org/layouts_and_rendering.html#rendering-by-default-convention-over-configuration-in-action)。 –

相關問題