Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

undefined method `find_by_profile_name'

Hi all,

I keep getting this error message when I try to go to a users page.

NoMethodError in ProfilesController#show undefined method `find_by_profile_name'

class ProfilesController < ApplicationController def show @user = User.find_by_profile_name(params[:id]) if @user @posts = Post.all render actions: :show

Any help would be greatly appreciated! Thanks

4 Answers

  user = User.find_by_profile_name(params[:name]) 

To find this user, we need profile_name column in users table. See if in schema.rb like this..

  create_table "users", force: true do |t|
    t.string   "profile_name"

Since you are getting an undefined method error on find_by_profile_name, it seems that you may not have profile_name as an attribute. Could you post your schema.rb file if you are still having troubles?

Also, check out the markdown cheatsheet linked below the reply box for info on how to format code. It makes things much easier to read.

You can also use

user = User.where(profile_name: params[:id]).take

Thank you everyone! You're suggestions helped.