Upgrade to Rails 3.1.1 and Authlogic - ruby-on-rails

Just have upgraded my rails app to Rails 3.1.1 and have get the following error:
Routing Error
undefined method `filter_parameter_logging' for ApplicationController:Class
application_controller.rb:
class ApplicationController < ActionController::Base
protect_from_forgery
helper :all
helper_method :current_user_session, :current_user
filter_parameter_logging :password, :password_confirmation
...
Do you have any idea about this?
Thanks!

Add this line in application.rb
config.filter_parameters += [:password, :password_confirmation]
and remove filter_parameter_logging from application_controller as it is inoperative in Rails 3

Related

How to configure i18n pt-BR on ruby on rails App, getting an error

I am trying to configure pt-BR on ruby on rails using i18n.
I have added on the file config/application.rb
config.i18n.default_locale = :pt-BR
And on the controller controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :set_locale
def set_locale
I18n.locale = params[:lang] || I18n.default_locale
end
end
When i run rails s i get the error:
: uninitialized constant MyApp::Application::BR (NameError)
If i change the :pt-BR to :pt, for example, it works fine, but not working with pt-BR
Any suggestions to fix that?
you should use quotes around :"pt-BR", instead of only :pt-BR.
try that:
config.i18n.default_locale = :"pt-BR"
source:
https://guiarails.com.br/i18n.html

alias_method': undefined method `current_user'

Hi i tried to implement forest_admin gem in rails 5 application
When i generate install with this command
rails g forest_liana:install <ENVIRONMENT SECRET>
The logs are alias_method': undefined method current_user' for classApplicationController' (NameError)
My aplication Controller
class ApplicationController < ActionController::Base
skip_before_action :verify_authenticity_token
before_action :session_expirada, unless: :devise_controller?
before_action :set_attr_to_current_user, unless: :devise_controller?
layout :layout_by_resource
alias_method :devise_current_user, :current_user
include RedirectFromEmail
# Pundi Authorization filtros
include Pundit
#after_action :verify_authorized, unless: :devise_controller? , #except: :index
#to catch message error Pundit
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
end
What happend?
You are trying to alias the method ":devise_current_user" to ":current_user". IN your controller current_user is not defined. If you define current_user in your controller(see below) then you will not get this error.
def current_user
#logic to get a handle on current user goes here
end
Remove alias and just use regular devise current_user which is included by default

InvalidAuthenticityToken in Devise

I recently added a piece of code to my ApplicationController to set the timezone of the current block to the one specified by the user.
class ApplicationController < ActionController::Base
around_action :set_time_zone, if: :current_user
protect_from_forgery with: :exception
private
def set_time_zone(&block)
Time.use_zone(current_user.time_zone, &block)
end
end
For some reason when I try to sign in i get a
ActionController::InvalidAuthenticityToken in Devise::SessionsController#create
If i remove
around_action :set_time_zone, if: :current_user
I can sign in and if i add it back after I sign in, everything works as expected.
Any ideas?
This page has good info on the problem, but I was weirdly able to fix this in Rails 5 by putting protect_from_forgery above the around_action/filter. Hope it helps!

Rails: Undefined method `flash' for ActionDispatch::Request

I'm trying to write an Ember application in Rails 4, and have decided to go with rails-api for the api controllers, while keeping the application controller intact for a few pages that aren't part of the single-page app. To put it in more concrete terms, here are my controllers:
app/controllers/application_controller.rb:
class ApplicationController < ActionController::Base
protect_from_forgery
end
app/controllers/sample_controller.rb:
class SampleController < ApplicationController
# my methods
end
app/controllers/api/v1/api_controller.rb:
class Api::V1::ApiController < ActionController::Api
include ActionController::MimeResponds
end
app/controllers/api/v1/sample_controller.rb:
module Api::V1
class SampleController < ApiController
respond_to :json
# my methods
end
end
My application.html.slim contains the following line:
== render partial: "flash_msgs" unless flash.blank?
The inclusion of which results in the following error:
undefined method 'flash' for #< ActionDispatch::Request:0x007f99f41d8720 >
Per discussion on this thread, it seems that the culprit could be rails-api, but I'm not entirely convinced given the inheritance I've set up. Any suggestions?
Not sure but maybe you need to include the ActionDispatch::Flash middleware to support the flash. Using:
config.middleware.use ActionDispatch::Flash
The docs says:
ActionDispatch::Flash: Supports the flash mechanism in
ActionController.
I hope it helps
See: https://github.com/plataformatec/devise/issues/2775
Inside devise.rb change
config.navigational_formats = ['*/*', :html]
to:
config.navigational_formats = [:json]
or just [ ]
If you're like me and creating an API on top of an existing application, you can add this to your config/application.rb file:
config.api_only = false
well, in my case my API mode rails app I had this code in one of my controller:
protect_from_forgery with: :null_session, if: Proc.new { |c| c.request.format == 'application/json' }
due to which handle_unverified_request was getting called that has this small piece of code request.flash = nil which was raising Undefined method 'flash' for ActionDispatch::Request for me.
Dealt with it by replacing protect_from_forgery with skip_before_action :verify_authenticity_token

Devise throwing exception when attempting to add parameter to sanitizer

I am following the instructions here in order to add two parameters to my sign up / registration form in a Ruby on Rails + devise based application: http://devise.plataformatec.com.br/#getting-started/strong-parameters
My controller is straight forward:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
before_filter :authenticate_user!
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :username
end
end
The error I'm getting is the following:
NoMethodError in Devise::SessionsController#new
undefined method `<<' for {}:ActionController::Parameters
Am I using the wrong version of Devise or something? I have gem 'devise', :git => 'https://github.com/plataformatec/devise', :branch => 'v3.0' specified in my Gemfile, nothing else is out of the ordinary.
This feature requires Devise 3.1.0.rc according to an issue opened on the Devise repo.

Resources