User has_many Goals, only want the new goal to show on edit screen

11 views
Skip to first unread message

Bob Larrick

unread,
Sep 2, 2015, 8:49:36 PM9/2/15
to SimpleForm
 <%= f.simple_fields_for :goals do |goal| %>
...
<% end %>

Shows inputs for all goals, both the existing ones and the new one set up in the controller with  @user.goals.build.

How can I only show inputs for the new one, and not the existing ones?

Carlos Antonio da Silva

unread,
Sep 3, 2015, 6:41:34 AM9/3/15
to plataformate...@googlegroups.com
You should be able to pass in the object you want instead. Please take a look at the fields_for documentation in Rails, Simple Form pretty much delegates to it: http://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-fields_for

Hope that helps.

--
You received this message because you are subscribed to the Google Groups "SimpleForm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-simp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

Bob Larrick

unread,
Sep 3, 2015, 9:41:38 AM9/3/15
to SimpleForm
Thanks!

I ended up doing something like

<% if goal.object.new_record? %>


and that seems to be working well.



On Thursday, September 3, 2015 at 6:41:34 AM UTC-4, Carlos Antonio da Silva wrote:
You should be able to pass in the object you want instead. Please take a look at the fields_for documentation in Rails, Simple Form pretty much delegates to it: http://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-fields_for

Hope that helps.
On Wed, Sep 2, 2015 at 9:49 PM, Bob Larrick <lar...@gmail.com> wrote:
 <%= f.simple_fields_for :goals do |goal| %>
...
<% end %>

Shows inputs for all goals, both the existing ones and the new one set up in the controller with  @user.goals.build.

How can I only show inputs for the new one, and not the existing ones?

--
You received this message because you are subscribed to the Google Groups "SimpleForm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-simpleform+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

Carlos Antonio da Silva

unread,
Sep 3, 2015, 9:43:45 AM9/3/15
to plataformate...@googlegroups.com
Yeah, it will, although it'll be possibly slower if you have many associated objects, because it'll process all records just to render a single one. But again as you said, it works, so whether it's good enough or not is up to the context it's in :)

On Thu, Sep 3, 2015 at 10:41 AM, Bob Larrick <lar...@gmail.com> wrote:
Thanks!

I ended up doing something like

<% if goal.object.new_record? %>


and that seems to be working well.



On Thursday, September 3, 2015 at 6:41:34 AM UTC-4, Carlos Antonio da Silva wrote:
You should be able to pass in the object you want instead. Please take a look at the fields_for documentation in Rails, Simple Form pretty much delegates to it: http://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-fields_for

Hope that helps.
On Wed, Sep 2, 2015 at 9:49 PM, Bob Larrick <lar...@gmail.com> wrote:
 <%= f.simple_fields_for :goals do |goal| %>
...
<% end %>

Shows inputs for all goals, both the existing ones and the new one set up in the controller with  @user.goals.build.

How can I only show inputs for the new one, and not the existing ones?

--
You received this message because you are subscribed to the Google Groups "SimpleForm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-simp...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio

--
You received this message because you are subscribed to the Google Groups "SimpleForm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-simp...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
At.
Carlos Antonio
Reply all
Reply to author
Forward
0 new messages