Advertisement
twinfacer

another sample controller code

Jun 28th, 2013
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 2.31 KB | None | 0 0
  1. class VectorsController < ApplicationController
  2.   respond_to :html, :js
  3.  
  4.   def show
  5.     @vector = Vector.find(params[:id])
  6.     @vector.increment!(:popularity)
  7.   end
  8.  
  9.   def index
  10.     respond_to do |format|
  11.       format.js do
  12.         @tab_name = params[:tab]
  13.         if @tab_name == "popular"
  14.           @vectors = Vector.popular.page params[:page]
  15.         else
  16.           @vectors = Vector.recent.page params[:page]
  17.         end
  18.         render "shared/vectors_list"
  19.       end
  20.       format.html do
  21.         @vectors = Vector.recent.page params[:page]
  22.         @popular_vectors = Vector.popular.page params[:page]
  23.         render "shared/vectors_list"
  24.       end
  25.     end
  26.   end
  27.  
  28.   def free_vectors
  29.     @simple_header = "Free vectors"
  30.     respond_to do |format|
  31.       format.js do
  32.         @tab_name = params[:tab]
  33.         if @tab_name == "popular"
  34.           @vectors = Vector.popular.free.page params[:page]
  35.         else
  36.           @vectors = Vector.recent.free.page params[:page]
  37.         end
  38.         render "shared/vectors_list"
  39.       end
  40.       format.html do
  41.         @vectors = Vector.recent.free.page params[:page]
  42.         @popular_vectors = Vector.popular.free.page params[:page]
  43.         render "shared/vectors_list"
  44.       end
  45.     end
  46.   end
  47.  
  48.   def free_download
  49.     user = User.get_by_email(params[:free_download][:email])
  50.     vector = Vector.free.find(params[:vector_id])
  51.     order = Order.create(user_id: user.id)
  52.     cart = Cart.create(order_id: order.id)
  53.     LineItem.create(cart_id: cart.id, vector_id: vector.id, licence_type: "free")
  54.     cart.send_to_user
  55.     flash[:notice] = "All is OK!"
  56.     redirect_to root_path
  57.   end
  58.  
  59.   def similar_vectors
  60.     @simple_header = "Similar vectors"
  61.     @vector = Vector.find(params[:vector_id])
  62.     respond_to do |format|
  63.       format.js do
  64.         @tab_name = params[:tab]
  65.         if @tab_name == "popular"
  66.           @vectors = @vector.similar_vectors.popular.page params[:page]
  67.         else
  68.           @vectors = @vector.similar_vectors.recent.page params[:page]
  69.         end
  70.         render "shared/vectors_list"
  71.       end
  72.       format.html do
  73.         @vectors = @vector.similar_vectors.recent.page params[:page]
  74.         @popular_vectors = @vector.similar_vectors.popular.page params[:page]
  75.         render "shared/vectors_list"
  76.       end
  77.     end
  78.   end
  79.  
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement