Reputation: 167
I am working on a rails 3.0.11 application. for a many to many association I used simple_fields_for
in a form.
simple_form_for @test do |f|
f.input :example
f.simple_fields_for :services do |builder|
render "services_partial", :f => builder
end
end
Now this is the main form and I used simple_fields_for
in the form to render the partial of many to many association model called services
In the services partial
f.input :example_service
f.another_service
What I want to do is to assign the value of example_service
attribute to a variable like
var = @test.services.example_service
but this method is not correct. Can anyone help me that how I can access this for each service. because there may be multiple services.
Upvotes: 0
Views: 3048
Reputation: 236
I do not quite understand what you're doing. But if you want the values of "example_service" of all services of given @test you can try this
some_var = @test.services.collect(&:example_service)
some_var is an array of "example_service"-values of all services
Upvotes: 1