Skip to content

Loading…

Passing block to association does not work on belongs_to #50

Closed
denispeplin opened this Issue · 4 comments

4 participants

@denispeplin

Model code

class MbbUnit < ActiveRecord::Base
  belongs_to :mbb_consumer
  ...
end

view code:

  <%= s.association :mbb_consumer do |c| %>
    <%= c.name %>
  <% end %>

It does not actually matter what I'm putting inside block, to_s method always called on 'parent' model.

I also checked has_many association with block, and it works as expected.

@nashby

I think that ability to pass block with argument is for has_many associations. For belongs_to you can use :using option

<%= a.association :artist, :using => :name_with_title %>
@denispeplin

Thanks! If there no other ways to do this, I will try this approach. But I need to pass block with helpers, and I'm not sure it is right way to use helpers inside model.

@carlosantoniodasilva

@denispeplin if it does not work out of the box, please feel free to send a patch adding this feature. Thanks!

@denispeplin

Finally found some time to fix this. Hope the patch is not too bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.