Skip to content

Instantly share code, notes, and snippets.

@Znow
Created December 28, 2011 12:53
Show Gist options
  • Save Znow/1527846 to your computer and use it in GitHub Desktop.
Save Znow/1527846 to your computer and use it in GitHub Desktop.
= form_for([:admin, @stock]) do |f|
- if @stock.errors.any?
#error_explanation
%h2
= pluralize(@stock.errors.count, "error")
prohibited this stock from being saved:
%ul
- @stock.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :value, "Værdi"
%br/
= f.number_field :value
.field
= f.label :month, "Måned"
%br/
= f.number_field :month
.field
= f.label :year, "År"
%br/
= f.number_field :year
.field
= f.fields_for([:admin, Investor]) do |fi|
= fi.collection_select(:investor, :id, Investor.all, :id, :name, {:prompt => 'Vælg investor'})
%br/
.actions
= f.submit "Gem"
def create
@stock = Stock.new(params[:stock])
@is = InvestorStock.new(params[:stock][:investor])
respond_to do |format|
if @stock.save
@is.stock_id = @stock.id
@is.save
format.html { redirect_to admin_stock_url(@stock), notice: 'Stock was successfully created.' }
format.json { render json: @stock, status: :created, location: @stock }
else
format.html { render action: "new" }
format.json { render json: @stock.errors, status: :unprocessable_entity }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment