Reputation: 5619
I've got the following routes.rb
resources :api_users, :as => :users
get '/:controller(/:action(/:id))'
post "/:controller(/:action(/:id))"
get '/' => 'startsites#startsite'
I call the following action in application_controller.rb:
def change_locale
if Settings.language_supported?(params[:locale])
session[:locale] = params[:locale]
I18n.locale = params[:locale]
end
case params[:goto]
when "user"
if current_user.nil?
redirect_to :action => :home
else
redirect_to :controller => :users
end
when "lecturer"
if current_user.nil?
redirect_to :action => :home
else
redirect_to :controller => :lecturers
end
else
redirect_to :startsites => :startsite
end
end
and I got this error:
No route matches [GET] "/settings/change_locale"
how can I solve this?
Upvotes: 0
Views: 48
Reputation: 789
The first path "/settings" assumes that there is settings controller and second looks for settings controller action i.e. change_locale. You are defining change_locale in applicationcontroller and sending a get request to settings controller which is not defined. Therefore the error occur No route matches [GET] "/settings/change_locale"
This could be a solution
class SettingsController < ApplicationController
def change_locale
if Settings.language_supported?(params[:locale])
session[:locale] = params[:locale]
I18n.locale = params[:locale]
end
end
And in route file
get '/settings/change_locale'
Upvotes: 1
Reputation: 6122
You just need to define the SettingsController
:
class SettingsController < ApplicationController
def change_locale
render text: 'it should be ok now'
end
end
It can't be just a method in the ApplicationController
.
Upvotes: 2