Skip to content

Instantly share code, notes, and snippets.

@mhinton
Last active September 25, 2015 16:08
Show Gist options
  • Save mhinton/948345 to your computer and use it in GitHub Desktop.
Save mhinton/948345 to your computer and use it in GitHub Desktop.
fields_for issue
# publications/:id/edit
def edit
@publication = CgPublisher::Publication.find(params[:id], :include => [{:version => { :work => :authorships }}, {:imprint => :subscriptions}])
end
# edit.html.erb
<% form_for @publication, :html => {:multipart => true} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>
# _form.html.erb
<% f.fields_for @publication.imprint.institutional_subscriptions do |builder| %>
<%= render "sub", :f => builder %>
<% end -%>
# _sub.html.erb
<div style="border: solid 1px black;">
<%= f.object.subscription_type.name %>
<%= f.object.subscription_type.subscriber_type %>
<%= f.object.subscription_type.cb_classification %>
<%= f.text_field :price, :size => 7, :value => "%.2f" %(f.object.price.to_f/100) %>
<%= f.hidden_field :id, :value => f.object.id %>
<%= f.hidden_field :subscription_type_id, :value => f.object.subscription_type_id %>
<%= f.hidden_field :media_type_id, :value => @media_type %>
</div><br/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment