【问题标题】:NoMethodError at adding redirection to routes.rb on Refinery CMS在 Refinery CMS 上向 routes.rb 添加重定向时出现 NoMethodError
【发布时间】:2015-01-13 09:53:15
【问题描述】:

由于从旧路径重定向到新路径,我添加到了 routes.rb:

Refinery::Core::Engine.routes.prepend do
  get 'about.html', to: redirect('/about')
end

mount Refinery::Core::Engine, at: '/'

结果没有重定向到'/about'并引发NoMethodError:

NoMethodError - undefined method `valid_encoding?' for :en:Symbol:
  actionpack (4.1.9) lib/action_dispatch/routing/redirection.rb:23:in `block in call'

actionpack (4.1.9) lib/action_dispatch/routing/redirection.rb:23:

req.symbolized_path_parameters.each do |key, value|
  unless value.valid_encoding? # <= L23
    raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}"
  end
end

当打开'localhost:3000/about.html'时

使用 gems:refinerycms 3.0.0,rails 4.1.9

有解决这个问题的想法吗?

【问题讨论】:

  • 你能发布关于页面的控制器代码吗?
  • 你为什么打开 /about.html 而不是 /about
  • @Daisuke Terada - 与炼油厂有完全相同的问题并重定向 404。你找到解决办法了吗?

标签: ruby-on-rails refinerycms


【解决方案1】:

从您发布的内容来看,您缺少一件事,那就是控制器代码。在 about_controller.rb 中尝试以下操作。

def find_page
    @page = ::Refinery::Page.find_by_link_url("/about")
end

【讨论】:

  • 感谢您的回复。关于页面是作为 Refinery::Page 的记录创建的。我希望打开 /about.html 将重定向到 /about。未找到 Refinery::Page.find_by_link_url("/about")。 :link_url 在 about 页面中为空白。关于页面:` - 在 Refinery CMS /admin/pages 上创建 - 并将“关于”输入到 :title - 发布为 url "localhost:3000/about" `
【解决方案2】:

@asgeo1 最后我找到了另一个解决方案。我的解决方案是由high_voltage 创建静态页面。 我猜在这种情况下,Refinery::Pages 无法同时保持重定向和动态路由。

  • 停止将 RefineryCMS 挂载到根目录并挂载到“/cms”
  • 创建 /app/views/pages/about.html.erb,以便发布为“/about”。参考:high_voltage:Usage

按照路线.rb:

  mount Refinery::Core::Engine, at: '/cms'
  get 'about.html', to: redirect('/about')

如果您还需要通过 Refinery::Pages 管理页面,请在 RefineryCMS 上创建“/about”页面,

关注app/views/pages/about.html.erb:

<% @page = Refinery::Pages.find_by(link_url: '/about') %>
<%= raw @page.content_for(:body) %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    相关资源
    最近更新 更多