POST /products POST /products.json
# File app/controllers/products_controller.rb, line 26 def create @product = Product.new(product_params) respond_to do |format| if @product.save format.html { redirect_to @product, notice: 'Product was successfully created.' } format.json { render action: 'show', status: :created, location: @product } else format.html { render action: 'new' } format.json { render json: @product.errors, status: :unprocessable_entity } end end end
DELETE /products/1 DELETE /products/1.json
# File app/controllers/products_controller.rb, line 61 def destroy @product.destroy respond_to do |format| format.html { redirect_to products_url } format.json { head :no_content } end end
GET /products/1/edit
# File app/controllers/products_controller.rb, line 21 def edit end
GET /products GET /products.json
# File app/controllers/products_controller.rb, line 6 def index @products = Product.all end
GET /products/new
# File app/controllers/products_controller.rb, line 16 def new @product = Product.new end
GET /products/1 GET /products/1.json
# File app/controllers/products_controller.rb, line 12 def show end
PATCH/PUT /products/1 PATCH/PUT /products/1.json
# File app/controllers/products_controller.rb, line 45 def update respond_to do |format| if @product.update(product_params) format.html { redirect_to @product, notice: 'Product was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @product.errors, status: :unprocessable_entity } end end end
START:#who_bought
# File app/controllers/products_controller.rb, line 70 def who_bought @product = Product.find(params[:id]) @latest_order = @product.orders.order(:updated_at).last if stale?(@latest_order) respond_to do |format| format.html format.xml format.atom format.json { render json: @product.to_json(include: :orders) } end end end