Just learning Rails trying to get a handle on something in a very
basic sense:
I can create a login tool, I can create a funciton that creates a
table based on skills but I have no idea how to make skills local to
each user? I was every used to have a list of skills that when they
login are displayed… Each user can’t have his own database table can
he? What is the general way of handling this.
Walker
On Jul 8, 6:37 pm, WalkerW [email protected] wrote:
Just learning Rails trying to get a handle on something in a very
basic sense:
I can create a login tool, I can create a funciton that creates a
table based on skills but I have no idea how to make skills local to
each user? I was every used to have a list of skills that when they
login are displayed… Each user can’t have his own database table can
he? What is the general way of handling this.
My answer is going to be a bit vague, since your question is a bit
vague. If you skills table has a user_id column then a user’s skills
are simply those with the appropriate user_id. Rails’ associations
will do most of this for you
class Skill
belongs_to :user
end
class User
has_many :skills
end
some_user.skills => The skills for that user
Fred
You can also map the skill resources as being nested under users in
your routes.rb.
map.resources :users, :has_many => :skills
This would provide you a way to access a user’s skills with the
following URI:
http://localhost:3000/users/1/skills # The array of skills for a
user with id == 1
And you can build the URI with something like:
user_skills_url(user_id) ==> http://localhost:3000/users/1/skills
Note: assume user_id = 1
On Jul 8, 2:17 pm, Frederick C. [email protected]