Forum: Ruby on Rails create object after before_filter :authenticate_user!

Posted by oto iashvili (Guest)
on 2013-02-14 13:06
(Received via mailing list)
hi

I use devise and cancan

my model

class PostsController < ApplicationController
  before_filter :authenticate_user!, only: [:create, :update, :destroy]
...
end

so an unauthentificate user can access new post form. Now when
unauthentificate user submit new or edit forms, he is redirected to 
login
form. But when he logs in, his post is not save in database. Is there
anythings to do such as callback if I want the post to be saved ?

thanks
Posted by Iazel (Guest)
on 2013-02-19 13:01
(Received via mailing list)
The first solution that comes in my mind:
class PostsController < ApplicationController
  before_filter :authenticate_user!, only: [:create, :update, :destroy]

  def authenticate_user!
     session[:post] = params[:post] unless user_signed_in?
     super
  end
...
end

... and then you check if session[:post] is present, clear and store 
post.

Il giorno gioved 14 febbraio 2013 13:05:14 UTC+1, oto iashvili ha 
scritto:
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.