I am using a mysql db and I want to pull some info from the db. I think
my problem is that I am trying to get the data from an object that
doesn't exist in my MemberController. My code:
[code]
class MemberController < ApplicationController
def index
@login = User.find_by_login(params[:l])
flash[:notice] = @login + ", you've logged in successfully"
end
end
[/code]
the table in the db is the User table and it has a column of login.
I am using a mysql db and I want to pull some info from the db. I think
my problem is
You'll find it easier to get help here if you'll post the error message
that demonstrates your problem, along with the code that the error
message tells you is causing the problem.
that I am trying to get the data from an object that
doesn't exist in my MemberController. My code:
[code]
class MemberController < ApplicationController
def index
@login = User.find_by_login(params[:l])
flash[:notice] = @login + ", you've logged in successfully"
end
end
[/code]
However, in this case you may well have told us the probable cause of
the problem.
the table in the db is the User table and it has a column of login.
Rails' default is that the table name is a plural version of the model
name. That's because the Model typically represents a single record
from a table. So the table named Users holds lots of records that are
access via the User model.
Rails' default is that the table name is a plural version of the model
name. That's because the Model typically represents a single record
from a table. So the table named Users holds lots of records that are
access via the User model.
Im sorry the table name is users...here is the error message:
NoMethodError in MemberController#index
undefined method `+' for #<User:0x44d3ca4>
RAILS_ROOT: C:/Ruby/MyProjects/ipod-give-away.com
Application Trace | Framework Trace | Full Trace
class MemberController < ApplicationController
def index
@user= User.find_by_login(params[:l])
flash[:notice] = @user.login + ", you've logged in successfully"
end
end
You were calling the + method, which concatenates two string objects, on a User object. In your original code, the @login variable did not hold a string object, but a user object (returned by the call to User.find_by_login( … ).
Ruby was rightfully complaining that the + method was not defined on the user object. @user.login returns a string, which does have the + method and therefore you can concatenate with the rest of your string (in the flash message).
You were calling the + method, which concatenates two string objects, on
a
User object. In your original code, the @login variable did not hold a
string object, but a user object (returned by the call to
User.find_by_login( ... ).
Ruby was rightfully complaining that the + method was not defined on the
user object. @user.login returns a string, which does have the + method
and
therefore you can concatenate with the rest of your string (in the flash
message).
On Mon, Mar 9, 2009 at 7:59 PM, Chris Gunnels <
oooo ok in PHP (what im used to programming), I was assigning @login =
User.find_by_login(params[:l]) which would, in php, tell php the @login
is a string and not an object. I have to get used to everything being an
object in ruby.