I have two models, users and themes, that I'm currently joining in a HABTM association in a themes_users table. Basically, after a user creates a new theme, it becomes available to other users to select for their own use.
However, only the original creator of the theme should have the ability to edit it. So, I need to have some other ki...
so i am trying to save to a join table in a habtm relationship, but i am having problems.
from my view, i pass in a group id with:
= link_to "Create New User", new_user_url(:group => 1)
User model (user.rb)
class User < ActiveRecord::Base
has_and_belongs_to_many :user_groups
accepts_nested_attributes_for
:user_groups end
...
class Question < ActiveRecord::Base
belongs_to :author
end
class Author < ActiveRecord::Base
has_many :questions
end
When I find some questions, I usually need to get their authors at the same time, so I use:
Question.find(:all, :include=>:authors)
But I don't write the ":include" part everywhere. I hope I can define the "inc...
Sorry for the semi-generic title, but I'm still pretty new at rails and couldn't think of a succinct way to put the question.
I have a basic habtm model setup: a Project has many Resources and a Resource can have many Projects. I have the database and models setup properly, and can do everything I need to via the console, but I'm having...
I'm new to Rails and trying to create a has_and_belongs_to_many relationship between orders and items.
class Order < ActiveRecord::Base
has_and_belongs_to_many :items
end
class Item < ActiveRecord::Base
has_and_belongs_to_many :orders
end
Migration for Orders (not shown. very basic)
Migration for OrderItems:
class CreateItems ...
I have a HABTM relationship on one of my models. I'm using formtastic for my forms. On a new action when choosing to output my column (HABTM) as check_boxes I see all my options appear, however they are all checked on by default. Ideally I want them to not be selected on a new action. When I uncheck a few options and save them, I will se...
I'm running into a problem viewing a list of 'category' checkboxes when I try to nest them in a fields_for form.
I have a 'product' model that 'has_many' 'photos' which 'has_and_belongs_to_many' 'categories'. I'm pretty sure all my associations in my models are correct, as is my joins table for the 'photos' and 'categories' relations...
Hi, I have a situation where I have Products, Suppliers, ShoppingLists and Valuations.
A shopping_list consist of many valuations each with a product, an specific supplier and a price.
My models are as follows:
class Product < ActiveRecord::Base
has_many :valuations
has_many :shopping_lists, :through => :valuations
end
class Supp...
I have a User model, Person model and Company model.
a User has many companies through Person and vice versa.
But i would like to be able to populate People and Companies that are not tied to Users that can be tied later.
class User < ActiveRecord::Base
attr_accessible :name
has_many :people
has_many :companies, :through => :peo...
Hi,
I have this simple has_and_belongs_to_many association between users, which works perfectly.
However, I would like to add a friendship relation between all new users created and the first user (yup, just like MySpace's Tom), directly in the Create method:
def create
@user = User.new(params[:user])
if @user.save
@user.frie...
I have two tables with a many to many relationship that I am using has_and_belongs_to_many to define the association.
class Foo < ActiveRecord::Base
...
has_and_belongs_to_many :bar
...
end
class Bar < ActiveRecord::Base
...
has_and_belongs_to_many :foo
...
end
I also have the class defined to represent the join table
cl...