Skip to content


Passing block to association does not work on belongs_to #50

denispeplin opened this Issue · 4 comments

4 participants


Model code

class MbbUnit < ActiveRecord::Base
  belongs_to :mbb_consumer

view code:

  <%= s.association :mbb_consumer do |c| %>
    <%= %>
  <% 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.


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 %>

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.


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


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.