Why I can't override 'create' at Devise::SessionsController?

1,722 views
Skip to first unread message

hopewise

unread,
Nov 19, 2011, 11:57:08 AM11/19/11
to Devise
I have devise 1.4.8, and I am trying to override "create" at
Devise::SessionsController to execute some logic once user signed in.

Here is my class: (stored at \app\controllers\students
\sessions_controller.rb)

class Students::SessionsController < Devise::SessionsController
def create
# this method is not called
super
end
end
here is my routes.rb

devise_for :students, :controllers => { :sessions => "students/
sessions" }

class Devise::SessionsController i stored at:
D:\RailsInstaller\Ruby1.9.2\lib\ruby\gems\1.9.1\gems\devise-1.4.8\app
\controllers

but, overridden "create" is never called! instead, only the "create"
at super class is called

any idea ?

thiagocifani

unread,
Nov 19, 2011, 1:27:24 PM11/19/11
to plataforma...@googlegroups.com
I dont know if I am missing something, but Where is the method you want to call inside create method? You are calling just super, what should do what the devise do if you dont override anything! try to call any thing inside create and you will see that it will be called!


regards

2011/11/19 hopewise <as3...@gmail.com>

hopewise

unread,
Nov 19, 2011, 2:32:08 PM11/19/11
to Devise
I am using RubyMine, I tried to toggle a break point inside the
create, but, never called there, I am calling super, but, I thought to
put my logic inside the create it self, then call the super .. am I
doing any thing wrong ?

> <http://del.icio.us/thiagocifani>

thiagocifani

unread,
Nov 19, 2011, 4:21:00 PM11/19/11
to plataforma...@googlegroups.com
Nops! In my project I do exactly the same! I inherit sessionscontroller from devise and in the action create I make something like this:

def create
foo

super

end


and it works for me!


regards

Carlos Antonio da Silva

unread,
Nov 20, 2011, 7:13:33 AM11/20/11
to plataforma...@googlegroups.com
I believe it should work fine with this config, I couldn't get anything wrong at a glance, just make sure you restart the server.
--
At.
Carlos Antonio

hopewise

unread,
Nov 21, 2011, 1:23:13 PM11/21/11
to Devise
I tried to restart the server, and I have the same result, only
"create" at the super class is called, I am still not able to override
it :-(
As you didn't see any thing wrong in the code I've listed in this
thread, could the view be the cause of problem ?
May be the form is posting for the super class and ignoring my
implementation ??

Here is the view:

<h2>Sign in </h2>

<%= form_for(resource, :as => resource_name, :url =>
session_path(resource_name)) do |f| %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>

<div><%= f.label :password %><br />
<%= f.password_field :password %></div>

<% if devise_mapping.rememberable? -%>
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></
div>
<% end -%>

<div><%= f.submit "Sign in" %></div>
<% end %>

<%= render :partial => "devise/shared/links" %>


On Nov 20, 2:13 pm, Carlos Antonio da Silva


<carlosantoniodasi...@gmail.com> wrote:
> I believe it should work fine with this config, I couldn't get anything
> wrong at a glance, just make sure you restart the server.
>

> > <http://del.icio.us/thiagocifani>
>
> --
> At.
> Carlos Antonio

hopewise

unread,
Nov 21, 2011, 1:55:32 PM11/21/11
to Devise
I have run the rake routes, I found that the sign in matched to devise
class! not my class,
I've fixed it like this:
devise_for :students do post '/students/sign_in' => 'students/
sessions#create' end

and deleted all other lines for :students at routes.rb, and it worked!

On Nov 20, 2:13 pm, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:

> I believe it should work fine with this config, I couldn't get anything
> wrong at a glance, just make sure you restart the server.
>

Reply all
Reply to author
Forward
0 new messages