有没有办法将空参数传递给rails中的辅助路径?
具体做法是:
get 'movies/director/:director', to: 'movies#search_by_director', as: :search_by_director
如果接受导演的网址为空( / movies / director / ),我希望 search_by_director_path(nil)仍然运行 search_by_director < / em>动作,我会处理那里的零值
目前,当我使用nil导演尝试 search_by_director_path(@ movie.director)时会发生什么:
没有路线匹配{:action =&gt;“search_by_director”,:controller =&gt;“movies”,:director =&gt;“”,:id =&gt;“1”}缺少必需的键:[:director]
答案 0 :(得分:0)
get 'movies/director/(:director)', to: 'movies#search_by_director', as: :search_by_director
怎么样?