polymorphic-associations

Nested simple_form with polymorphic association. Unpermited parameter

自作多情 提交于 2019-12-12 06:01:57
问题 It's a lot of question about it all around, but I can't find the answer. I've: group.rb class Group < ActiveRecord::Base has_many :descriptions, :as => :describable accepts_nested_attributes_for :descriptions end description.rb class Description < ActiveRecord::Base belongs_to :describable, :polymorphic => true end groups_controller.rb def update @group = Group.find(params[:id]) if @group.update_attributes(group_params) flash[:success] = "yes" redirect_to groups_path else render 'edit' end

polymorphic_path not generating correct path

瘦欲@ 提交于 2019-12-12 04:35:18
问题 I am trying to user a rails method called polymorphic_path but I am getting the wrong url. My polymorphic association is with Students and Landlords who are both Users through userable. Here are my models: class User < ActiveRecord::Base belongs_to :userable, polymorphic: true end class Student < ActiveRecord::Base has_one :user, :as => :userable end class Landlord < ActiveRecord::Base has_one :user, :as => :userable end I have a variable called current_user holding the User object. The

Ruby Polymorphic association working locally but not in heroku

耗尽温柔 提交于 2019-12-12 04:18:52
问题 Similar issue of the question below, but need a different solution ActionView::Template::Error (undefined method...) Works locally, but not on Heroku My polymorphic association Address>Account is working locally, but when I upload it to Heroku I get the following error when rendering the view: Rendered addresses/show.html.erb within layouts/application (101.1ms) 2016-01-09T03:04:14.947013+00:00 app[web.1]: 2016-01-09T03:04:14.947015+00:00 app[web.1]: ActionView::Template::Error (undefined

How to test polymorphic controllers in Rails 2.3?

大憨熊 提交于 2019-12-11 11:31:36
问题 Dear fellow Overflowers, I will try to give the essence of my issue. Thanks in advance for your patience. My Polymorphic Controller ( Appointments ) is accessed by two Views , the first belongs to Admin::Doctor namespace and the second one to Patient namespace. the relevant part of the routes.rb : map.resources :patient do |patients| patients.resources :appointments end map.namespace(:admin) do |admin| admin.resources :doctor do |doctors| doctors.resources :appointments end end So, I can now

Rails association with delegate methods. possible bug with AR?

北城余情 提交于 2019-12-11 07:57:50
问题 Isolated this question into it's own rails app: and added a git repo as an example Module: module SeoMeta def self.included(base) base.extend(ClassMethods) base.send :include, InstanceMethods end module ClassMethods def is_seo_meta has_one :meta, class_name: SeoMetum, as: :metumable, dependent: :destroy, autosave: true delegate :browser_title, :meta_description, :meta_author, :meta_keywords, :browser_title=, :meta_keywords=, :meta_description=, :meta_author=, to: :meta after_save :save_meta

Rails convention for a polymorphic model + controller

自闭症网瘾萝莉.ら 提交于 2019-12-11 07:11:35
问题 I have users, groups, and pages. Each record can have pictures. Here is my architecture: Polymorphic model for Pictures . Users, groups, and pages are picturable . Nested pictures controller for each of users, groups, and pages (e.g. users/5/pictures ) Is this the most standard set up? Am I forgetting any Rails convention? routes.rb example looks like this: resources :users do resources :pictures pictures_controller.rb looks like this: class PicturesController < ApplicationController before

Rails: How to create polymorphic relationship/friendship model

假装没事ソ 提交于 2019-12-11 06:53:19
问题 I want to create a polymorphic friendship/network system. For example User can request or be requester to join multiple models like: Company Project Group Contacts(friends) Some will be one to many e.g. a user is employed by one company but a company has many employees. Others many to many e.g a user has many projects a project has many users The relationships aren't to difficult to create using active recorded. The middle step, requesting(invitations) that has me baffled. After bit of

PostgreSQL: How to return dynamic rows from table without using “column definition list”?

試著忘記壹切 提交于 2019-12-11 06:43:58
问题 How to retrieve rows from table dynamically without using "column definition list"? I am trying to do same by using polymorphic type "anyelement"(pseudo type) but getting error "structure of query does not match function result type". For example: I have table called "table1" which consist of following details. --Table create table table1 ( slno integer, fname varchar, lname varchar, city varchar, country varchar ) --Function create or replace function function1(column_name varchar,relation

Finding record where polymorphic association or nil

青春壹個敷衍的年華 提交于 2019-12-11 02:52:51
问题 I have a rails app running ruby 2.1.2 and rails 4.1.1 and in it I have a polymorphic association like so: class Picture < ActiveRecord::Base belongs_to :imageable, polymorphic: true end class Employee < ActiveRecord::Base has_many :pictures, as: :imageable end class Product < ActiveRecord::Base has_many :pictures, as: :imageable end I want to be able to find all Pictures that either belong to a given Employee or have no associated "imageable" record. # These both work fine Picture.where

Rails has_one association confusion

烈酒焚心 提交于 2019-12-11 02:48:03
问题 I am very new to Rails and I want to create a Person model that has one Address and a Company Model that has one Address and one Person. Here is what I've done so far $ rails generate model Address street:string suburb:string $ rails g scaffold Person name:string address:references $ rails g scaffold Company name:string person:references address:references class Address < ActiveRecord::Base belongs_to :person belongs_to :company end class Person < ActiveRecord::Base has_one :address end class