I have a Class Foo has many Bar(s)
I have a form which contains the nested class Bar and when the form submits I would like Bar that was built to have an IP address associated to it from the server. My issue is I do not know how to call a method through params to set the IP in Bar when Foo is created
In the Foo controller
def new
@foo = Foo.new
@foo.bars.build
end
def create
@foo.Foo.create(params[:foo])
if @foo save
#error code
#b = Bar.find(params[:bar_id])
# b.setIP request.remote_ip
end
end
Form
<%= form_for @foo do |f| %>
<%= f.label "Comment : " %>
<%= f.fields_for :bars do |comment_form| %>
<%= comment_form.text_area :comment %>
<%= f.label "Terms of Service" %>
<%= comment_form.check_box :terms %>
<% end %>
<%= f.submit "Submit"%>
<% end %>