【问题标题】:rails 4: how do I use url_for with a resource?rails 4:如何将 url_for 与资源一起使用?
【发布时间】:2015-12-28 19:49:23
【问题描述】:

将应用程序从 Rails 2 迁移到 4,因为我的服务器通过 rails 应用程序被黑客入侵,因此出于安全原因我正在升级。在我的代码中,我有这一行:

lawyer_show_url = "<%= url_for(:controller => 'lawyers', :action => 'show') %>";

我现在收到此错误消息:

ActionView::Template::Error (No route matches {:action=>"show", :controller=>"lawyers"}):

在 config/routes.rb 中,带有 rails 2 和 4,我有这一行:

resource :lawyers

我的旧 config/routes.rb 文件也有臭名昭著的包罗万象:

map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

但我知道在 rails 4 中没有这样的代码。 如何在 rails 4 中为我的资源生成 URL?

【问题讨论】:

    标签: ruby-on-rails-4 routing


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 2013-09-19
      • 1970-01-01
      • 2015-08-19
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      相关资源
      最近更新 更多