0

I have a User model, where users have a username, and User has_one :profile

I want to make a route so that if a person goes to "http://www.website.com/username" it goes to profile#show.

at the bottom of my routes, i have:

match ":username" => "profiles#show"

But, it's not finding the ID of the profile, which I expected.

ActiveRecord::RecordNotFound in ProfilesController#show
Couldn't find Profile without an ID

I just am not sure how to properly make the route so i get the id of the user from the :username

thanks

Joel Grannas
  • 2,016
  • 2
  • 24
  • 46

1 Answers1

2

You're passing :username in params. You need to find the Profile based on the associated User model's :username. In your action:

@profile = User.find_by_username(params[:username]).profile
deefour
  • 34,974
  • 7
  • 97
  • 90
  • you rock, sir! Can you take a look at my last comment on your answer to this question: http://stackoverflow.com/questions/14654010/squeel-and-rails-dynamic-where-clause – Joel Grannas Feb 22 '13 at 17:15