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

habtm in rails 4.1 #379

Closed
markmcdonald51 opened this issue Jan 9, 2015 · 7 comments
Closed

habtm in rails 4.1 #379

markmcdonald51 opened this issue Jan 9, 2015 · 7 comments

Comments

@markmcdonald51
Copy link

Hi,

I am trying to use the habtm feature of rails in activescaffold. I didnt think this would be so troublesome and at this point i am not sure if i am finding a bug or not doing something right in AS. So i have a very simple model that has a habtm like such...

class MultinationalCompany < ActiveRecord::Base
has_and_belongs_to_many :stock_exchange_countries
end

When i try to list (or do anything with this AS controller now I get:

Showing /home/mark/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/active_scaffold-3.4.11/app/views/active_scaffold_overrides/_list_record.html.erb where line #12 raised:

undefined method `multinationalcompanies_stock_exchange_countries' for #MultinationalCompany:0x007f17798182f0

undefined method `multinationalcompanies_stock_exchange_countries' for #MultinationalCompany:0x007f17798182f0

<% columns.each do |column| %> <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> <%= content_tag :td, column_attributes(column, record).merge(:class => column_class(column, column_value, record)) do %> <%= authorized ? render_list_column(column_value, column, record) : column_value %>

I know this works because i can add items to the habtm tables via console. Just not sure why AS is looking for a method like this.

Thanks in advance.
mark

@scambra
Copy link
Member

scambra commented Jan 9, 2015

Remove backtrace silencers (config/initializers/backtrace_silencers.rb) and post trace of error

@markmcdonald51
Copy link
Author

ctivemodel (4.1.0) lib/active_model/attribute_methods.rb:435:in method_missing' activerecord (4.1.0) lib/active_record/attribute_methods.rb:206:inmethod_missing'
active_scaffold (3.4.11) lib/active_scaffold/helpers/list_column_helpers.rb:114:in format_column_value' active_scaffold (3.4.11) lib/active_scaffold/helpers/list_column_helpers.rb:9:inget_column_value'
active_scaffold (3.4.11) app/views/active_scaffold_overrides/_list_record.html.erb:12:in block in __home_mark__rbenv_versions_______lib_ruby_gems_______gems_active_scaffold________app_views_active_scaffold_overrides__list_record_html_erb___3105910987985982313_69869546993240' active_scaffold (3.4.11) app/views/active_scaffold_overrides/_list_record.html.erb:10:ineach'
active_scaffold (3.4.11) app/views/active_scaffold_overrides/_list_record.html.erb:10:in __home_mark__rbenv_versions_______lib_ruby_gems_______gems_active_scaffold________app_views_active_scaffold_overrides__list_record_html_erb___3105910987985982313_69869546993240' actionview (4.1.0) lib/action_view/template.rb:145:inblock in render'
activesupport (4.1.0) lib/active_support/notifications.rb:161:in instrument' actionview (4.1.0) lib/action_view/template.rb:339:ininstrument'
actionview (4.1.0) lib/action_view/template.rb:143:in render' actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:399:inblock in collection_with_template'
actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:395:in map' actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:395:incollection_with_template'
actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:291:in render_collection' actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:275:inblock in render'
actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:in block in instrument' activesupport (4.1.0) lib/active_support/notifications.rb:159:inblock in instrument'
activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.1.0) lib/active_support/notifications.rb:159:ininstrument'
actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:in instrument' actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:274:inrender'
actionview (4.1.0) lib/action_view/renderer/renderer.rb:47:in render_partial' actionview (4.1.0) lib/action_view/renderer/renderer.rb:21:inrender'
actionview (4.1.0) lib/action_view/helpers/rendering_helper.rb:32:in render' active_scaffold (3.4.11) lib/active_scaffold/extensions/action_view_rendering.rb:117:inrender_with_active_scaffold'
active_scaffold (3.4.11) app/views/active_scaffold_overrides/_list.html.erb:28:in __home_mark__rbenv_versions_______lib_ruby_gems_______gems_active_scaffold________app_views_active_scaffold_overrides__list_html_erb___4008054611595093047_69869539520080' actionview (4.1.0) lib/action_view/template.rb:145:inblock in render'
activesupport (4.1.0) lib/active_support/notifications.rb:161:in instrument' actionview (4.1.0) lib/action_view/template.rb:339:ininstrument'
actionview (4.1.0) lib/action_view/template.rb:143:in render' actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:306:inrender_partial'
actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:279:in block in render' actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:inblock in instrument'
activesupport (4.1.0) lib/active_support/notifications.rb:159:in block in instrument' activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:ininstrument'
activesupport (4.1.0) lib/active_support/notifications.rb:159:in instrument' actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:ininstrument'
actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:278:in render' actionview (4.1.0) lib/action_view/renderer/renderer.rb:47:inrender_partial'
actionview (4.1.0) lib/action_view/renderer/renderer.rb:21:in render' actionview (4.1.0) lib/action_view/helpers/rendering_helper.rb:32:inrender'
active_scaffold (3.4.11) lib/active_scaffold/extensions/action_view_rendering.rb:117:in render_with_active_scaffold' active_scaffold (3.4.11) app/views/active_scaffold_overrides/_list_with_header.html.erb:34:in__home_mark__rbenv_versions_______lib_ruby_gems_______gems_active_scaffold________app_views_active_scaffold_overrides__list_with_header_html_erb___854878120151472022_69869521979360'
actionview (4.1.0) lib/action_view/template.rb:145:in block in render' activesupport (4.1.0) lib/active_support/notifications.rb:161:ininstrument'
actionview (4.1.0) lib/action_view/template.rb:339:in instrument' actionview (4.1.0) lib/action_view/template.rb:143:inrender'
actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:306:in render_partial' actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:279:inblock in render'
actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:in block in instrument' activesupport (4.1.0) lib/active_support/notifications.rb:159:inblock in instrument'
activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.1.0) lib/active_support/notifications.rb:159:ininstrument'
actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:in instrument' actionview (4.1.0) lib/action_view/renderer/partial_renderer.rb:278:inrender'
actionview (4.1.0) lib/action_view/renderer/renderer.rb:47:in render_partial' actionview (4.1.0) lib/action_view/renderer/renderer.rb:21:inrender'
actionview (4.1.0) lib/action_view/helpers/rendering_helper.rb:32:in render' active_scaffold (3.4.11) lib/active_scaffold/extensions/action_view_rendering.rb:117:inrender_with_active_scaffold'
active_scaffold (3.4.11) app/views/active_scaffold_overrides/list.html.erb:1:in __home_mark__rbenv_versions_______lib_ruby_gems_______gems_active_scaffold________app_views_active_scaffold_overrides_list_html_erb__230370648139568578_69869517175140' actionview (4.1.0) lib/action_view/template.rb:145:inblock in render'
activesupport (4.1.0) lib/active_support/notifications.rb:161:in instrument' actionview (4.1.0) lib/action_view/template.rb:339:ininstrument'
actionview (4.1.0) lib/action_view/template.rb:143:in render' actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:55:inblock (2 levels) in render_template'
actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:in block in instrument' activesupport (4.1.0) lib/active_support/notifications.rb:159:inblock in instrument'
activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.1.0) lib/active_support/notifications.rb:159:ininstrument'
actionview (4.1.0) lib/action_view/renderer/abstract_renderer.rb:38:in instrument' actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:54:inblock in render_template'
actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:62:in render_with_layout' actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:53:inrender_template'
actionview (4.1.0) lib/action_view/renderer/template_renderer.rb:17:in render' actionview (4.1.0) lib/action_view/renderer/renderer.rb:42:inrender_template'
actionview (4.1.0) lib/action_view/renderer/renderer.rb:23:in render' actionview (4.1.0) lib/action_view/rendering.rb:99:in_render_template'
actionpack (4.1.0) lib/action_controller/metal/streaming.rb:217:in _render_template' actionview (4.1.0) lib/action_view/rendering.rb:82:inrender_to_body'
actionpack (4.1.0) lib/action_controller/metal/rendering.rb:32:in render_to_body' actionpack (4.1.0) lib/action_controller/metal/renderers.rb:32:inrender_to_body'
actionpack (4.1.0) lib/abstract_controller/rendering.rb:25:in render' actionpack (4.1.0) lib/action_controller/metal/rendering.rb:16:inrender'
actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:41:in block (2 levels) in render' activesupport (4.1.0) lib/active_support/core_ext/benchmark.rb:12:inblock in ms'
/home/mark/.rbenv/versions/2.1.3/lib/ruby/2.1.0/benchmark.rb:294:in realtime' activesupport (4.1.0) lib/active_support/core_ext/benchmark.rb:12:inms'
actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:41:in block in render' actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:84:incleanup_view_runtime'
activerecord (4.1.0) lib/active_record/railties/controller_runtime.rb:25:in cleanup_view_runtime' actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:40:inrender'

@scambra
Copy link
Member

scambra commented Jan 9, 2015

What is your active_scaffold config block in that controller? It seems like trying to display multinationalcompanies_stock_exchange_countries column instead of stock_exchange_countries

@markmcdonald51
Copy link
Author

Hi Sergio,

this one is pretty simple actually...it looks to be getting the
tableize/constantize mixed up as if this was going to be a method like
the error states shouldn't it be 'multinational_companies_stock_exchanges'
and not multinationalcompanies? I fished around a bit with the stacktrace
and went into the gem trying to look for where this takes place but decided
not to get to deep...

class MultinationalCompaniesController < ApplicationController

active_scaffold :"multinational_company" do |config|
config.label = 'Multinational Companies'
config.columns.exclude(:shareholder_relationships, :created_at,
:updated_at)

   # trying different things here but they are commented out because it

makes no diff....
# :stock_exchange_countries, :stock_exchanges,
# config.columns[:stock_exchange_countries].form_ui = :multi_select

end
end

On Fri, Jan 9, 2015 at 10:34 AM, Sergio Cambra notifications@github.com
wrote:

What is your active_scaffold config block in that controller? It seems
like trying to display multinationalcompanies_stock_exchange_countries
column instead of stock_exchange_countries


Reply to this email directly or view it on GitHub
#379 (comment)
.

@scambra
Copy link
Member

scambra commented Jan 9, 2015

Try to exclude :multinationalcompanies_stock_exchange_countries column
Rails 4.1 changes internal of habtm, it works like a has_many through with a new has_many with intermediate model. multinationalcompanies_stock_exchange_countries column can be that association created by ActiveRecord.

I haven't used ActiveScaffold with Rails 4.1 yet because of some rails 4.1 bug, I have only tested against rails 4.1 with some automated tests, although many features are not tested yet. Maybe that internal association will be excluded by default in the future.

@markmcdonald51
Copy link
Author

Good call Scambra! That worked. Now if i could just figure out how to create a multi-select out of this i would be in business! I already tried the form_ui = :multi_select (from the api) but it didnt seem to work.

I excluded these:

:multinationalcompanies_stock_exchange_countries)

config.columns.exclude( :multinationalcompanies_stock_exchanges,
:multinationalcompanies_stock_exchange_countries)

and it worked.... then added:

   config.columns[:stock_exchange_countries].form_ui = :select
   config.columns[:stock_exchanges].form_ui = :select

and i at least get the checkboxes for the ui. Just wish i could have multiselect which is a rather useful form ui for this cause.

THanks for all you help, again Scrambra!

cheers
mark

@scambra
Copy link
Member

scambra commented Jan 12, 2015

There is no :multi_select form_ui. There is a :multi_select search_ui but it's displayed as checkbox list too, and it's only for singular associations where you want to allow searching for multiple values.

You can enable draggable lists with:

config.columns[:stock_exchanges].options = {:draggable_lists => true}

It's not the same but it's better than checkboxes. Also, you can create your own override for that column in your helper. Or create your own form_ui in ApplicationHelper, named like active_scaffold_input_multi_select(column, html_options)

@scambra scambra changed the title habtm habtm in rails 4.1 Feb 5, 2015
@scambra scambra closed this as completed May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants