0

My Devise + Omniauth setup currently uses the following path to log a user in using Facebook:

user_omniauth_authorize_path(:facebook)

I have a partial that displays a list of items, each item having a link that:

1) logs the user in with the above path if not logged in

2) links to the item show page if they are logged in

If not logged in, I'd like to modify #1 to redirect the item show page of the particular item that was clicked on after login.

This would require passing the id of the item into the Omniauth controller somehow.

Any suggestions?

neon
  • 2,811
  • 6
  • 30
  • 44

1 Answers1

0

No, it is done in a simpler way.

In your item controller set a before_filter

class ItemController < ApplicationController
  before_filter :authenticate_user!
end

Then render all your links as links to items, something like this:

<%= link_to 'item', item_path(@item) %>

In this case, if user is not logged in and tries to view some item, he's redirected to login page, and after login he's redirected back to the item he wanted to view.

This approach also ensures that your items cannot be viewed unless user is logged in (even if he, say, copied a link to item and sent it to a friend, who doesn't have account on your site).

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367