Skip to content

Instantly share code, notes, and snippets.

@coffeencoke
Created September 11, 2009 19:03
Show Gist options
  • Save coffeencoke/185509 to your computer and use it in GitHub Desktop.
Save coffeencoke/185509 to your computer and use it in GitHub Desktop.
# PUT /buckets/Animals
# PUT /buckets/Animals.json
# Used for creating and updating buckets
# view the features located at /features/buckets.*.feature
# for details on the design of this method.
def update
@bucket = Bucket.find_or_new_by_name params[:id]
if @bucket.new_record?
if @bucket.save
respond_to do |format|
format.html do
flash[:success] = "Bucket was successfully created."
redirect_to @bucket
end
format.json{ render :json => '', :status => 201 }
end
else
respond_to do |format|
format.html{ render :action => :new }
format.json{ render :json => '', :status => 500 }
end
end
else
if @bucket.update_attributes(params[:bucket])
respond_to do |format|
format.html do
flash[:success] = "Bucket was successfully updated."
redirect_to @bucket
end
format.json{ render :json => @bucket, :status => 200 }
end
else
respond_to do |format|
format.html{ render :action => :edit }
format.json{ render :json => '', :status => 500 }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment