Reputation: 5860
users_controller.rb
class UsersController < ApplicationController
def index
render_404
end
def show
@user = User.where(:username => params[:username])
render_404 if !@user
end
end
basically i want to get each user data based on their username because later i want to include one more table which has meta-data for each user but i keep getting the following error
undefined method `username' for #<ActiveRecord::Relation:0x007fb5dbc52ea0>
Extracted source (around line #1):
1: <%= @user.username %> profile page
Upvotes: 0
Views: 220
Reputation: 11967
@user = User.where(:username => params[:username]).first
try this or @user = User.find_by_username(params[:username])
. Where
returns AR::Relation
, not an ActiveRecord object.
Upvotes: 2