Created
May 3, 2014 21:44
-
-
Save karlingen/7e261291b6b014f6a959 to your computer and use it in GitHub Desktop.
Reform gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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