associations

Extending windows explorer context menu

孤者浪人 提交于 2019-12-23 03:41:51
问题 I'm having hard times figuring out why this doesn't work on my computer. I've read this article http://msdn.microsoft.com/en-us/library/bb776820.aspx and tried it, and it works for an unknown file type, but for know such as .bmp it doesn't - I've also deleted other keys under .bmp - didn't help. I've tried this in HKEY_CLASSES_ROOT.bmp and in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts.bmp I need to implement this in my program so it has custom context menu

association data in rails model scope

谁都会走 提交于 2019-12-22 23:47:22
问题 I have a model named Post (blog post) and a model named Category . Each post belongs_to a category. Each category has an attribute named retainer that specifies the amount of time before a post "expires", so for example movies_category.retainer = 30.days What I'm trying to do is create a scope for Post that finds all of the posts which are "expired". So for example, assuming I were to hardcode the value of 30.days and it were to apply to all categories (therefore all posts), the scope would

association and migration between users and teams (rails)

只愿长相守 提交于 2019-12-22 11:30:31
问题 I have this User and team model which has the following association: user.rb class User < ActiveRecord::Base belongs_to :team team.rb class Team < ActiveRecord::Base has_many :users has_one :leader, class_name: "User", foreign_key: "leader_id" belongs_to :manager, class_name: "User", foreign_key: "manager_id" but it seems that I can't imagine representing it properly into a migration. At first, this is what I did: class AddTeamIdToUsers < ActiveRecord::Migration def change add_column :users,

How to create a new record for a many-to-many through association that accepts nested attributes?

冷暖自知 提交于 2019-12-22 10:24:05
问题 Organization and User have a many-to-many association through Relationship . Initially I implemented this a 1-to-many association, which worked but now I need it to become a many-to-many through association. So I created the Relationship model and changed the association in the model files. Organization accepts nested attributes for User as in my app I have a joined signup form for the two. Also, I use it in my seeds file: Organization.create!(name: "name", ...).users.create(email: "email

Create association between two instancied objects

江枫思渺然 提交于 2019-12-22 04:52:23
问题 I have two models: (Albums and Product) 1) Inside Models Inside album.rb: class Album < ActiveRecord::Base attr_accessible :name has_many :products end Inside product.rb: class Product < ActiveRecord::Base attr_accessible :img, :name, :price, :quantity belongs_to :album end 2) Using " rails console ", how can I set the associations (so I can use "<%= Product.first.album.name %>")? e.g. a = Album.create( :name => "My Album" ) p = Product.create( :name => "Shampoo X" ) # what's next? how can i

Hibernate: Why is binding for a field similar weather explicit @JoinColum annotation is used or not?

北慕城南 提交于 2019-12-21 22:04:07
问题 Is @JoinColum implicitly specified when we use any association type annotation like @OneToOne , @OneToMany , etc. Here is snippet from Student entity in association with Laptop entity Case 1) Without using explicit @JoinColum @OneToMany(cascade=CascadeType.ALL) private List<Laptop> laptops=new ArrayList<Laptop>(); Case 2) Using explicit @JoinColum @OneToMany(cascade=CascadeType.ALL) @JoinColumn private List<Laptop> laptops=new ArrayList<Laptop>(); When I check DEBUG both cases have "almost"

How to create fixtures with foreign key alias in rails?

妖精的绣舞 提交于 2019-12-21 22:02:28
问题 I have two models, App and User , where an App has a creator who is a User . # app.rb class App < ActiveRecord::Base belongs_to :creator, class_name: 'User' end # user.rb class User < ActiveRecord::Base has_many :apps, foreign_key: "creator_id" end How do I create fixtures for this? I tried: # apps.yml myapp: name: MyApp creator: admin (User) # users.yml admin: name: admin But this doesn't work, since the relation is an aliased foreign key, not a polymorphic type. Omitting the (User) in the

No route matches with Nested Resources

霸气de小男生 提交于 2019-12-21 21:33:10
问题 I have two associated tables. Venues and Specials . A venue can have many specials . Once a user has created a venue I wish to allow them to create a special on the venues#index page. By using nested resources I have achieved the desired URL: /venues/5/specials/new . However, my current code results with: No route matches {:controller=>"specials", :format=>nil} I'm guessing the error is with my SpecialsController and the def new and def create functions. I would like the URL to take me to a

New model object through an association

陌路散爱 提交于 2019-12-21 12:41:23
问题 I thought it was possible to create a new model object through an association. class Order < ActiveRecord::Base belongs_to :basket end class Basket < ActiveRecord::Base has_one :order end order = Order.new() basket = order.basket.new() # NoMethodError: undefined method `new' for nil:NilClass 回答1: It is, but your syntax is a little wrong: class Order < ActiveRecord::Base belongs_to :basket end class Basket < ActiveRecord::Base has_one :order end order = Order.new() basket = order.create_basket

Rails 3 build a select tag with has_many belongs_to association

戏子无情 提交于 2019-12-21 08:37:59
问题 Based on following models class Company < ActiveRecord::Base belongs_to :country end class Country < ActiveRecord::Base has_many :companies end I want to have in my companies/_form a select tag containing all the countries I think that the Company.new(params[:company]) in companies_controller#create can create the association between company and the selected country I'm running rails 3.0.0, what is the best way to achieve that? thanks for your insights 回答1: collection_select should do the