class ProductsController
Public Instance Methods
create()
click to toggle source
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 :show, status: :created, location: @product } else format.html { render :new } format.json { render json: @product.errors, status: :unprocessable_entity } end end end
destroy()
click to toggle source
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, notice: 'Product was successfully destroyed.' } format.json { head :no_content } end end
edit()
click to toggle source
GET /products/1/edit
# File app/controllers/products_controller.rb, line 21 def edit end
index()
click to toggle source
GET /products GET /products.json
# File app/controllers/products_controller.rb, line 6 def index @products = Product.all end
new()
click to toggle source
GET /products/new
# File app/controllers/products_controller.rb, line 16 def new @product = Product.new end
show()
click to toggle source
GET /products/1 GET /products/1.json
# File app/controllers/products_controller.rb, line 12 def show end
update()
click to toggle source
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 { render :show, status: :ok, location: @product } else format.html { render :edit } format.json { render json: @product.errors, status: :unprocessable_entity } end end end
who_bought()
click to toggle source
START:who_bought
# File app/controllers/products_controller.rb, line 71 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