polymorphic-associations

Rails polymorphic link for nested index action

社会主义新天地 提交于 2019-12-14 03:46:33
问题 I have been trying to find this one link for hours now. I have a polymorphic association where both collections & assortments have designs. Collection model has_many :designs, :as => :targetable Assortment model has_many :designs, :as => :targetable Design model belongs_to :targetable, :polymorphic => true In order to link to the design's 'show' action, the proper polymorphic path would be: link_to polymorphic_path([@targetable, @design]) But I can't figure out how to link to the design's

Form with Rails polymorphic association for user sign-up

跟風遠走 提交于 2019-12-13 08:26:43
问题 I had problems with forms using polymorphic association for an user sign-up. I want to show fields from multiple models of polymorphic association, but I can't. Model Classes: class User < ActiveRecord::Base devise ... belongs_to :userable, :polymorphic => true end class Advisor < ActiveRecord::Base has_one :user, :as => :userable attr_accessible :extra accepts_nested_attributes_for :user # Idon't know if it is ok end class AnotherKingOfUser < ActiveRecord::Base #the same.. end I want to make

Attempting to avoid polymorphic associations

流过昼夜 提交于 2019-12-13 05:24:30
问题 I'm creating a MySQL database and I ran into an instance in which I needed polymorphic associations... Obviously SQL does not support this, so I decided to create a column for each foreign key; found below: CREATE TABLE mixers ( mixers_id INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NOT NULL, 0_booze_id INT(11), 0_gen_booze_id INT(11), 0_gen_soda_id INT(11), 0_soda_id INT(11), 1_booze_id INT(11), 1_gen_booze_id INT(11), 1_gen_soda_id INT(11), 1_soda_id INT(11), 2_booze_id

Rails polymorphic comments undefined method user_name

别来无恙 提交于 2019-12-13 05:01:25
问题 So I followed the Railscast 154 about implementing polymorphic associations and I was able to get it up and running, but whenever I try to call the user who commented I get an undefined method. Here's my Migration: class CreateComments < ActiveRecord::Migration def change create_table :comments do |t| t.text :content t.belongs_to :commentable, polymorphic: true t.references :member t.timestamps end add_index :comments, [:commentable_id, :commentable_type] add_index :comments, :member_id end

How do I create a polymorphic 1:1 relationships wtih Ember Data fixtures?

a 夏天 提交于 2019-12-13 04:19:40
问题 Page has a polymorphic 1:1 relationship with a model called PageContent. PageContent has two subtypes (TextOnly and Video). I want to be able to able to do a findAll for "page" and get all of the content back. What am I doing wrong? JSBin 回答1: This seems to work: http://jsbin.com/names/1/edit Only wrong thing I could see is the App.Page.FIXTURES. It should be: App.Page.FIXTURES = [ { id: 1, title: "Introduction", pageContent: 1, pageContentType: "textOnly" },{ id: 2, title: "Summary",

PK on table with (simulated) polymorphic association

一个人想着一个人 提交于 2019-12-13 02:06:11
问题 I am trying to set up the right indices on a table I have just created which contains 4 "polymorphic associations" and a PK ID . The 4 associations allow me not to have to quadruple the number of tables to the addition I am making to the database and should not be modified in this discussion. My question is how should I set up the indices so that I get optimal performance (speed, space not so much) ? None of the 4 keys is candidate for PK. More specifically all 4 are but only one at a time. I

Rails: Polymorphic assosiation and accepts_nested_attributes

烈酒焚心 提交于 2019-12-12 10:19:55
问题 The attachment won't save. What I am missing here? In my application I have a project ,for each project user can upload many assets. The Upload is done by carrier wave. here are the models class Project < ActiveRecord::Base has_many :assets,:as => :assetable,dependent: :destroy accepts_nested_attributes_for :assets, :allow_destroy => true end class Asset < ActiveRecord::Base belongs_to :project belongs_to :user belongs_to :assetable, :polymorphic => true mount_uploader :attachment,

Rails nested polymorphic form with javascripting

谁说我不能喝 提交于 2019-12-12 10:19:33
问题 I want the following on my form: Degree is polymorphic partial with has_many relation to profile. This partial is called by main form - profile. By pressing 'Add a Qualification' user can add as many degrees. I've been able to attach only one degree to profile which is the last one others are all ignored. I even know why it's happening because link_to is not able to pass profile instance. so I have to create new profile in degrees_controller as you can see in my code here. Can final profile

Laravel saving mass assignment with a morphMany relation

喜你入骨 提交于 2019-12-12 09:56:36
问题 I'm looking at mass assignment in Laravel, and trying to mass assign data for both one model and it's related model. My models: class News extends Eloquent { protected $table = 'news'; protected $fillable = array( 'title', 'slug', 'author', 'img', 'content', ); public function content() { return $this->morphMany('Content', 'morphable')->orderBy('section'); } } class Content extends Eloquent { protected $table = 'contents'; protected $fillable = array( 'rawText', 'section', ); public function

Does Ransack support the same polymorhpic belongs_to associations in its searches as MetaSearch does?

时间秒杀一切 提交于 2019-12-12 09:52:56
问题 I am migrating from the MetaSearch gem to the Ransack gem for an upgrade to Rails 3.1 and I am having problems with my searches for polymorphic associations. The existing MetaSearch syntax isn't working for Ransack, but I couldn't find any documentation mentioning any syntax changes. Or whether this feature is supported in Ransack. For example, from the MetaSearch github page, given the following classes: class Article < ActiveRecord::Base has_many :comments, :as => :commentable end class