Skip to content

Instantly share code, notes, and snippets.

@jmarmolejos
Last active December 17, 2015 00:10
Show Gist options
  • Save jmarmolejos/5518995 to your computer and use it in GitHub Desktop.
Save jmarmolejos/5518995 to your computer and use it in GitHub Desktop.
# GET /companies/1
# GET /companies/1.json
def show
@company = Company.find(params[:id])
respond_with @company
end
# POST /companies
# POST /companies.json
def create
@company = Company.new(params[:company])
if @company.save
respond_with @company, location => @company
else
result = {:success => false}
respond_with result, :location => @company, :status => :unprocessable_entity
end
end
# PUT /companies/1
# PUT /companies/1.json
def update
@user = Company.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:company])
format.json { head :no_content }
else
format.json { render json: @user.errors, status: :unprocessable_entity }
format.xml { render xml: @user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /companies/1
# DELETE /companies/1.json
def destroy
@company = Company.find(params[:id])
@company.destroy
respond_with ({:success => true})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment