2015-02-06 43 views
1

環境:重定向不工作,因爲我在Rails中很期待

Rails: 3.2.12 
Ruby: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux] 

在我的routes.rb,我有:

match '/attendance', to: "attendance#attendance_dashboard" 
match '/check_in', to: "attendance#check_in" 

在我attendance_controller.rb,我有:

def attendance_dashboard 
    @registered_and_not_checked_in = get_registered_and_not_checked_in() 
end 

def check_in 
    logger.info("Email: #{params["party"]["email"]}") 
    redirect_to attendance_url 
end 

當我對myapp/attendance進行操作時,它的行爲應該像它應該的那樣,並顯示一個表格,每行中的最後一個字段是出席聯繫人的鏈接troller的check_in動作和params包括哈希派對。

當我點擊鏈接,我404具體來說,這裏的test.log中所說的話(該記錄信息是要確保我沒有轟炸,直到重定向):

Processing by AttendanceController#check_in as HTML 
    Parameters: {"party"=>{"email"=>"[email protected]", "event_id"=>"3", "first"=>"Rrr", "last"=>"Rrrrr", "payment"=>"0.0", "transaction_id"=>""}} 
    [1m[35mBlogPost Load (0.4ms)[0m SELECT `blog_posts`.* FROM `blog_posts` 
    [1m[36mUser Load (0.4ms)[0m [1mSELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1[0m 
Email: [email protected] 
Completed 404 Not Found in 5ms 

我也嘗試以下重定向語法:

redirect_to attendance_path 

我錯過了什麼?

路線:

這是耙路線的輸出:

  /attendance(.:format) attendance#attendance_dashboard 
check_in  /check_in(.:format) attendance#check_in 

注意,不像CHECK_IN,沒有「路徑」,即使在routes.rb中的語法是相同的

+1

'rake routes'的輸出是什麼?出席率是否顯示爲路線? – alephtwo 2015-02-06 20:27:36

+0

看我的編輯。我不明白爲什麼出席和check_in之間的路線產生的方式有所不同。請注意,根據我最初的問題,我可以做my_app /考勤,它將我帶到正確的地方 – EastsideDeveloper 2015-02-06 20:40:22

回答

3

你應該在你的路線文件中有這個:

match '/attendance', to: "attendance#attendance_dashboard", :as => :attendance 
match '/check_in', to: "attendance#check_in", :as => :check_in 
+0

這工作。我仍然不明白爲什麼這條路線適用於check_in,但不適合出席 – EastsideDeveloper 2015-02-06 21:52:46