Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

belongs_to form issue #3828

Closed
navjeetc opened this issue Mar 4, 2015 · 9 comments
Closed

belongs_to form issue #3828

navjeetc opened this issue Mar 4, 2015 · 9 comments
Assignees

Comments

@navjeetc
Copy link

navjeetc commented Mar 4, 2015

I have a model

class Consent < ActiveRecord::Base
  belongs_to :disclosed_from_org, :class_name => "Organization", :foreign_key => "disclosed_from_orid"
  belongs_to :disclosed_to_org, :class_name => "Organization", :foreign_key => "disclosed_to_orid"
end

With this code in Active Admin edit form, it shows both two dropdowns for Organizations as well as two additional text fields for disclosed_from_orid and disclosed_to_orid and no matter. How to hide showing id fields. With this no matter what I choose in dropdown, it sets the org ids in consent model to the values in text fields.

@seanlinsley
Copy link
Contributor

@navjeetc this is the reason: #4298 (comment)

@timoschilling
Copy link
Member

That's can't be the reason. content_columns filter _id, but his fields ends with _orid.

@timoschilling timoschilling reopened this Feb 18, 2016
@timoschilling
Copy link
Member

@navjeetc is this still a issue for you?

@seanlinsley
Copy link
Contributor

@timoschilling they're saying that the ID is showing up, and the don't want it to show up. So it's the reverse of #4298 (comment)

@Fivell
Copy link
Member

Fivell commented Feb 5, 2017

so looks like we should implement own content_columns that works better for our needs

@Fivell
Copy link
Member

Fivell commented Feb 11, 2017

created ticket in formtastic repo for tracking

@Fivell
Copy link
Member

Fivell commented Feb 11, 2017

There is a solution now. Not sure if we need to create PR for this untill get answer from formtastic mantainers.

ActiveAdmin::FormBuilder is inherited from Formtastic::FormBuilder
we can override default_columns_for_object with

ActiveAdmin::FormBuilder.class_eval do
  def default_columns_for_object
    assoc_columns  = association_columns(:belongs_to)
    cnt_columns = content_columns
    klass = @object.class
    # remove custom foreign keys from content columns to prevent duplicated inputs
    if assoc_columns.present?
      cnt_columns -=  klass.reflections.map {|_,v| v.options[:foreign_key] }.compact
    end
    cols = asooc_columns + cnt_columns
    cols -= Formtastic::FormBuilder.skipped_columns
    cols.compact
  end
end

I will track it until formtastic provide more elegant way to fix this

@Fivell
Copy link
Member

Fivell commented Feb 13, 2017

@timoschilling , formtastic guys tell they will accept PR for v 4.0.

@Fivell
Copy link
Member

Fivell commented Feb 15, 2017

fixed by formtastic/formtastic#1241
until formtastic 4.0 this #3828 (comment) can be used

@Fivell Fivell closed this as completed Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants