user567665
user567665

Reputation:

how to redirect the user to their own page (ROR and Devise Gem)

ok, bear with me here, please.

i'm asking a question in which i'm not fully conversant of all the technical details, etc. (in other words, please take it easy on me for not being fully up on the par).

i've created a ROR application with Devise's gem ... it allows you to sign in, sign up, and log out.

it's very simple, and it just has a page in which you fill in your name, favorite hobby, & book. (hey, it's just an example)

i've also used their redirect code to go this page:

  def after_sign_in_path_for(resource)
    posts_path
  end

the thing is that ... this page is public to everyone who logs in.

how do i redirect the user to their own page? and not see everyone's else "notes."

i've looked around ... and Devise has a link on sessions_controllers ...

do i use that? i don't fully understand the purpose of it.

if yes, how? still trying to figure out how all the puzzle pieces fit together, and it's hard to do that when you don't have full understanding of the topic itself.

or is there another way that's simpler?

if this question is too broad, please let me know ... but i'm not really quite sure how to break it down.

in essence, what i'm really asking is how do i have a user be directed to their own page and not see anyone else's page.

thanks in advance for any help/advice/pointers/etc.

Upvotes: 0

Views: 156

Answers (2)

ichigolas
ichigolas

Reputation: 7725

Try with:

def after_sign_in_path_for(user) # note: user or w/e your model is named
  users_path(current_user)
end

Upvotes: 0

vich
vich

Reputation: 11896

First, let's assume your User model has_many :posts. In your PostsController index action (the default RESTful route would be posts_path) you can put something like this:

@posts = current_user.posts

and when visiting the index view you will only see the current user's posts.

That being said, you are not limited to the index view. You can customize any view you'd like and have a corresponding Controller action with declared instance variables which you can manipulate in your views.

Does that makes sense?

Upvotes: 1

Related Questions