views:

65

answers:

1

I have developed a blog application of sorts that I am trying to allow other users to take advantage of (for free and mostly for family). I wondering if the authentication I have set up will allow for such a thing. Here is the scenario.

Currently the application allows for users to sign up for an account and when they do so they can create blog posts and organize those posts via tags. The application displays no data publicly (another words, you have to login to see anything). To gain access you have to create an account and even after you do, you cannot see anyone else's information as the applications filters using the current_user method and displays in the /posts/index.html.erb page. This would be great if a user only wanted to blog and share it with themselves, not really what I am looking for.

My question has two parts (hopefully I won't make anyone mad by not putting these into two questions)

  1. Is it possible for a particular users data to live at www.myapplication.com/user without moving everything to the /user/show.html.erb file?
  2. Is it possible to make some of that information (living at the URL) public but still require login for create and destroy actions.

Essentially, exactly like twitter. I am just curious if I can get from where I am (using the current_user methods across controllers to display in /posts/index.html.erb) to where I want to be. My fear is that I have to redesign the app such that the user data lives in the /user/show.html.erb page.

Thoughts?

UPDATE: I am using Clearance for authentication by Thoughtbot. I wonder if there is something I can set in the vendored gem path to represent the /posts/index.html.erb code as the /user/id code and replace id with the user name.

A: 

For your first question, this is certainly doable. You just need to set up a route to do this. Here is one example that you might be able to us:

http://marcada.ms/2010/02/twitter-like-urls-for-user-accounts-in-ruby-on-rails/

For the second question, I am not familiar with Clearance but this is a fairly common practice. Basically in your view you check if the current logged in user is the same as the post author. If so then you display the links.

sosborn
This was great and seems to be working from the standpoint of routing. But how do I tell the show page to display the same thing that the current /posts/index.html.erb page is displaying? Do I have to recode that page to work in this view or is there a way to set it?
bgadoci
Ah, ok, just figured this out. Changed the route to go to posts controller action index.
bgadoci
Well, works great to get you to a page and display the @user information, but how do I handle the next step? For instance, when someone clicks a post title and it attempts to use the /posts/show.html.erb page, how do I set that?
bgadoci
Use the same routing technique that you used for the username.
sosborn