环境:
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时,它的行为应该是这样,并显示一个表格,每行中的最后一个字段是指向考勤控制器的check_in操作的链接,并且参数包括散列方。
当我点击链接时,我是404.具体来说,这是test.log所说的内容(记录器信息是为了确保在重定向之前我没有轰炸):
Processing by AttendanceController#check_in as HTML
Parameters: {"party"=>{"email"=>"rrrrr.rrr@gmail.com", "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: rrrrr.rrr@gmail.com
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中的语法是相同的
答案 0 :(得分:3)
你应该在你的路线文件中有这个:
match '/attendance', to: "attendance#attendance_dashboard", :as => :attendance
match '/check_in', to: "attendance#check_in", :as => :check_in