Search code examples
ruby-on-railsrefinerycms

NoMethodError at adding redirection to routes.rb on Refinery CMS


I added to routes.rb due to redirecting to new path from old path:

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

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

As a result, it was not redirected to '/about' and raise 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

when opened 'localhost:3000/about.html'

using gems: refinerycms 3.0.0, rails 4.1.9

Any idea for solving this problem?


Solution

  • @asgeo1 Finally I found another solution. My solution is that creating static pages by high_voltage. I guess in this case could not keep up both the redirection and dynamic routing by Refinery::Pages.

    • Stop mounting RefineryCMS on root and mount on '/cms'
    • Create /app/views/pages/about.html.erb, so that is published as '/about'. ref: high_voltage:Usage

    following the routes.rb:

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

    if you need also managing the page by Refinery::Pages, create '/about' page on RefineryCMS,

    following the app/views/pages/about.html.erb:

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