Курсовые - Разработка интернет-магазина канцелярских товаров

ПРИЛОЖЕНИЕ А

 

  • class ApplicationController < ActionController::Base

    before_action :configure_permitted_parameters, if: :devise_controller?

    protected
    def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up) {|u| u.permit(:username,:email,:password,:password_confirmation,:roll,:about) }
    devise_parameter_sanitizer.permit(:sign_in) {|u| u.permit(:username,:email,:password,:password_confirmation,:roll,:about) }

    end

    end
  •  

class BoughtsController < ApplicationController

def new
@wains = Wain.where(user_id: current_user.id)
@bought = current_user.boughts.build
end


def create
@bought = current_user.boughts.build(bought_params)
@bought.save
redirect_to users_page_path(current_user)
end
def destroy

@bought = Bought.find(params[:id])
@bought.destroy
redirect_to users_page_path(current_user)
end



private def bought_params
params.require(:bought).permit(:name,:number_tel,:street,:payment,:deliver,:last_name,:email,:username)
end


end

  •  

class CategoriesController < ApplicationController
before_action :authenticate_user!, except:[:index,:show]
before_action :set_category ,only: [:show,:edit,:update,:destroy]

def index
@categories=Category.all
end

def new
@category=Category.new
end

def show
end

class BoughtsController < ApplicationController

def new
@wains = Wain.where(user_id: current_user.id)
@bought = current_user.boughts.build
end


def create
@bought = current_user.boughts.build(bought_params)
@bought.save
redirect_to users_page_path(current_user)
end
def destroy

@bought = Bought.find(params[:id])
@bought.destroy
redirect_to users_page_path(current_user)
end



private def bought_params
params.require(:bought).permit(:name,:number_tel,:street,:payment,:deliver,:last_name,:email,:username)
end


end

def edit
end

def update
if @category.update_attributes(category_params)
redirect_to categories_path
else
render :edit
end
end

def create
@category = Category.new(category_params)

if @category.save
redirect_to @category
flash[:success] = "Успешно"
else
render :new
end
end

def destroy
@category.destroy
redirect_to categories_path
end

private def category_params
params.require(:category).permit(:name)
end
def set_category
@category=Category.find(params[:id])
end

end

  •  

class CharacteristicsController < ApplicationController
before_action :authenticate_user!, except:[:index,:show]
before_action :set_product, only: [:create, :update, :destroy]
def index

end

def new
@characteristic=Characteristic.new
end



def show
@product = Product.find(params[:id])
@characteristic = Characteristic.where(product_id: @product.id)
end

def createclass CategoriesController < ApplicationController
before_action :authenticate_user!, except:[:index,:show]
before_action :set_category ,only: [:show,:edit,:update,:destroy]

def index
@categories=Category.all
end

def new
@category=Category.new
end

def show
end

class BoughtsController < ApplicationController

def new
@wains = Wain.where(user_id: current_user.id)
@bought = current_user.boughts.build
end


def create
@bought = current_user.boughts.build(bought_params)
@bought.save
redirect_to users_page_path(current_user)
end
def destroy

@bought = Bought.find(params[:id])
@bought.destroy
redirect_to users_page_path(current_user)
end



private def bought_params
params.require(:bought).permit(:name,:number_tel,:street,:payment,:deliver,:last_name,:email,:username)
end


end

def edit
end

def update
if @category.update_attributes(category_params)
redirect_to categories_path
else
render :edit
end
end

def create
@category = Category.new(category_params)

if @category.save
redirect_to @category
flash[:success] = "Успешно"
else
render :new
end
end

def destroy
@category.destroy
redirect_to categories_path
end

private def category_params
params.require(:category).permit(:name)
end
def set_category
@category=Category.find(params[:id])
end

end

@characteristic = @product.characteristics.create(characteristic_params)
if @product.save
redirect_to @product
else
render :new
end
end

def destroy

@characteristic = Characteristic.find(params[:id])
@characteristic.destroy
redirect_to @product
end


def set_product
@product = Product.find(params[:product_id])
end

def characteristic_params
params.require(:characteristic).permit(:name,:about)
end

end

  •  

class ProductsController < ApplicationController
before_action :authenticate_user!, except:[:index,:show]

def index
@products=Product.where(["name LIKE ?","%#{params[:search]}%"]).order(params[:sort])
end


def show
@product=Product.find(params[:id])
end

def new

@product = Product.new
end
def edit
@product=Product.find(params[:id])
endclass CharacteristicsController < ApplicationController
before_action :authenticate_user!, except:[:index,:show]
before_action :set_product, only: [:create, :update, :destroy]
def index

end

def new
@characteristic=Characteristic.new
end



def show
@product = Product.find(params[:id])
@characteristic = Characteristic.where(product_id: @product.id)
end

def createclass CategoriesController < ApplicationController
before_action :authenticate_user!, except:[:index,:show]
before_action :set_category ,only: [:show,:edit,:update,:destroy]

def index
@categories=Category.all
end

def new
@category=Category.new
end

def show
end

class BoughtsController < ApplicationController

def new
@wains = Wain.where(user_id: current_user.id)
@bought = current_user.boughts.build
end


def create
@bought = current_user.boughts.build(bought_params)
@bought.save
redirect_to users_page_path(current_user)
end
def destroy

@bought = Bought.find(params[:id])
@bought.destroy
redirect_to users_page_path(current_user)
end



private def bought_params
params.require(:bought).permit(:name,:number_tel,:street,:payment,:deliver,:last_name,:email,:username)
end


end

def edit
end

def update
if @category.update_attributes(category_params)
redirect_to categories_path
else
render :edit
end
end

def create
@category = Category.new(category_params)

if @category.save
redirect_to @category
flash[:success] = "Успешно"
else
render :new
end
end

def destroy
@category.destroy
redirect_to categories_path
end

private def category_params
params.require(:category).permit(:name)
end
def set_category
@category=Category.find(params[:id])
end

end

@characteristic = @product.characteristics.create(characteristic_params)
if @product.save
redirect_to @product
else
render :new
end
end

def destroy

@characteristic = Characteristic.find(params[:id])
@characteristic.destroy
redirect_to @product
end


def set_product
@product = Product.find(params[:product_id])
end

def characteristic_params
params.require(:characteristic).permit(:name,:about)
end

end


def update
@product=Product.find(params[:id])
if @product.update_attributes(product_params)
redirect_to @product
else
flash[:error] = "Ошибка"
render :edit
end
end



def create
@product = Product.new(product_params)

if @product.save
redirect_to @product
flash[:success] = "Успешно"
else
flash[:error] = "Ошибка"
render :new
end
end


def destroy
@product=Product.find(params[:id])
@product.destroy
redirect_to new_search_path

end


private def product_params
params.require(:product).permit(:name,:body,:picture,:about,:cost,:url,:category_id,:image)
end



end

  •  

class SearchesController < ApplicationController

def new
@products=Product.where(["name LIKE ?","%#{params[:search]}%"]).order(params[:sort])
@search=Search.new

end
def create
@search=Search.create(search_params)
redirect_to @search
end
def show
@search=Search.find(params[:id])
end
private
def search_params
params.require(:search).permit(:keywords,:min_price,:max_price,:category_id)
end

end

  •  

class UsersPageController < ApplicationController
def index
@users=User.all
end

def show

@user = User.find(params[:id])
@boughts = Bought.where(user_id: @user.id)
end


def destroy
if current_user.roll =="admin" || current_user.username == @user.username
@user=User.find(params[:id])
@user.destroy
redirect_to new_search_path
else
redirect_to new_search_path
end
end

def edit
@user=User.find(params[:id])
end

def update
@user=User.find(params[:id])
if current_user.roll =="admin" || current_user.username == @user.username
if @user.update_attributes(user_params)
redirect_to users_page_path
else
render :edit
end
else
redirect_to users_page_path
end
end


private def user_params
params.require(:user).permit(:email,:username,:roll)
end
end

  •  

class WainsController < ApplicationController

before_action :set_post, only: [:new,:create, :update,:edit,:show]

def index

@wains = Wain.where(user_id: current_user.id)

end
def new

@wain = current_user.wains.build
end

def create
@wain = current_user.wains.build(wain_params)
@wain.save
redirect_to wains_path
end

def destroy

@wain=Wain.find(params[:id])
@wain.declass UsersPageController < ApplicationController
def index
@users=User.all
end

def show

@user = User.find(params[:id])
@boughts = Bought.where(user_id: @user.id)
end


def destroy
if current_user.roll =="admin" || current_user.username == @user.username
@user=User.find(params[:id])
@user.destroy
redirect_to new_search_path
else
redirect_to new_search_path
end
end

def edit
@user=User.find(params[:id])
end

def update
@user=User.find(params[:id])
if current_user.roll =="admin" || current_user.username == @user.username
if @user.update_attributes(user_params)
redirect_to users_page_path
else
render :edit
end
else
redirect_to users_page_path
end
end


private def user_params
params.require(:user).permit(:email,:username,:roll)
end
end
stroy
redirect_to wains_path

end

private def wain_params
params.require(:wain).permit(:name,:count,:id_product,:image,:cost)
end

def set_post
@product = Product.find(params[:product_id])
end

end

 

ПОЛНОЦЕННЫЙ код программы находится по ссылке: https://github.com/big-qqq/shopoop

 

Количество комментариев: 0

Для того, чтобы оставить коментарий необходимо зарегистрироваться