Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Last active December 11, 2015 00:19
Show Gist options
  • Save telagraphic/4516193 to your computer and use it in GitHub Desktop.
Save telagraphic/4516193 to your computer and use it in GitHub Desktop.
@current_account = signed_in_user.accounts.find(params[:account_id])
@new_credit = @current_account.credits.build(params[:account_id])
class User < ActiveRecord::Base
has_many :accounts
end
class Account < ActiveRecord::Base
belongs_to :user
has_many :credits
end
class Credit < ActiveRecord::Base
belongs_to :account
end
<h1>Add a credit to your account<h1>
<%= form_for [@current_account, @new_credit] do |f| %>
<div class="field">
<%= f.label :amount %><br />
<%= f.text_field :amount %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_field :description %>
</div>
<div class="actions"><%= f.submit %></div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment