Skip to content

Instantly share code, notes, and snippets.

@karlingen
Created May 3, 2014 21:44
Show Gist options
  • Save karlingen/7e261291b6b014f6a959 to your computer and use it in GitHub Desktop.
Save karlingen/7e261291b6b014f6a959 to your computer and use it in GitHub Desktop.
Reform gem
# Working:
def create
@form = SongForm.new(Song.new)
respond_to do |format|
if @form.validate(params[:song])
@form.save do |data, nested|
Song.create(nested)
end
format.html { redirect_to @form, notice: 'Song was successfully created.' }
format.json { render :show, status: :created, location: @form }
else
format.html { render :new }
format.json { render json: @song.errors, status: :unprocessable_entity }
end
end
end
# Not Working:
def create
@form = SongForm.new(Song.new)
respond_to do |format|
if @form.validate(params[:song])
@form.save
format.html { redirect_to @form, notice: 'Song was successfully created.' }
format.json { render :show, status: :created, location: @form }
else
format.html { render :new }
format.json { render json: @song.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