I want to override authenticate_user and current_user method of devise gem
You may be able to monkey-patch it like:
module Devise
module Controllers
module Helpers
def authenticate_user!
#do some stuff
end
end
end
end
But I would ask what the ultimate goal is, because Devise has some customizability built into it already, and overriding these methods makes me wonder "why use Devise at all?"
Rails Michael Hartl Tutorial + Devise current_user?
Devise gives you the current_user
helper by default. However, it doesn't give you current_user?
boolean method. You need to define this method yourself in application_helper.rb
:
def current_user?(user)
user == current_user
end
Now you have current_helper?
defined you can pass in your @user
instance variable
<% unless current_user?(@user) %>
<div id="follow_form">
<% if current_user.following?(@user) %>
<%= render 'unfollow' %>
<% else %>
<%= render 'follow' %>
<% end %>
</div>
<% end %>
Thats all you have to do. You don't have to touch your ApplicationController or SessionsHelper
in any way. You are simply using current_user
which Devise gives you in order to define current_user?(user)
. This way is much easier to implement. Hope this helps
skip_before_filter ignores conditionals
It is a Rails bug (or at least an undocumented strange behaviour). It is tracked here: https://github.com/rails/rails/issues/9703
In this thread, you can find a (twisted) solution.
Instead of
skip_before_filter :authenticate_user!, :only => :show, :if => :in_production
write
skip_before_filter :authenticate_user!, :only => :show
before_filter :authenticate_user!, :only => :show, :unless => :in_production
It worked for me.
Related Topics
How to Check Whether a Value in a String Is an Ip Address
Why Does Accessing a Ssl Site with Mechanize on Windows Fail, But on MAC Work
Fast Way to Get Remote Image Dimensions
Install Any Version of Ruby with Rvm on Mavericks
How to Remove Ruby from Ubuntu
Making Multiple Http Requests Asynchronously
Empty Attribute with Ruby Haml
Can Bundler Show Me Which Gems in Gemfile Have Newer Versions (Eg. Dry-Run of Bundle Update)
Hot Deploy on Heroku with No Downtime
Install Bundler Gem Using Ansible
Redis or Mongo for Determining If a Number Falls Within Ranges
Creating a Capistrano Task That Performs Different Tasks Based on Role
How to Make Carrierwave Delete the File When Destroying a Record
How to Fix Hanging Popen3 in Ruby