Best Active_mocker_ruby code snippet using Sort.where
user_games_controller.rb
Source:user_games_controller.rb
...11 @sort_attribute_2 = params[:sort_attribute_2]12 @filter = params[:filter]13 if @sort_attribute == "platform"14 if @filter == "name_up"15 @user_games = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("games.name").page(@page).per(@limit)16 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("games.name").page(@page.to_i + 1).per(@limit)17 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("games.name").page(@page.to_i + 2).per(@limit)18 elsif @filter == "name_down"19 @user_games = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("games.name DESC").page(@page).per(@limit)20 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("games.name DESC").page(@page.to_i + 1).per(@limit)21 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("games.name DESC").page(@page.to_i + 2).per(@limit)22 elsif @filter == "release_date_desc"23 @user_games = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date DESC").page(@page).per(@limit)24 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)25 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)26 elsif @filter == "release_date_asc"27 @user_games = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date ASC").page(@page).per(@limit)28 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date ASC").page(@page.to_i + 1).per(@limit)29 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date ASC").page(@page.to_i + 2).per(@limit)30 else31 @user_games = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order(created_at: :desc).page(@page).per(@limit)32 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order(created_at: :desc).page(@page.to_i + 1).per(@limit)33 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order(created_at: :desc).page(@page.to_i + 2).per(@limit)34 end35 elsif @sort_attribute == "genre"36 if @filter == "name_up"37 @user_games = current_user.user_games.joins(game: :genred_games).where(genred_games: {genre_id: @sort_attribute_2}).order("games.name").page(@page).per(@limit)38 @user_games_next = current_user.user_games.joins(game: :genred_games).where(genred_games: {genre_id: @sort_attribute_2}).order("games.name").page(@page.to_i + 1).per(@limit)39 @user_games_next_2 = current_user.user_games.joins(game: :genred_games).where(genred_games: {genre_id: @sort_attribute_2}).order("games.name").page(@page.to_i + 2).per(@limit)40 elsif @filter == "name_down"41 @user_games = current_user.user_games.joins(game: :genred_games).where(genred_games: {genre_id: @sort_attribute_2}).order("games.name DESC").page(@page).per(@limit)42 @user_games_next = current_user.user_games.joins(game: :genred_games).where(genred_games: {genre_id: @sort_attribute_2}).order("games.name DESC").page(@page.to_i + 1).per(@limit)43 @user_games_next_2 = current_user.user_games.joins(game: :genred_games).where(genred_games: {genre_id: @sort_attribute_2}).order("games.name DESC").page(@page.to_i + 2).per(@limit)44 elsif @filter == "release_date_desc"45 @user_games = current_user.user_games.joins(game: :genred_games).joins(game: :platformed_games).where(genred_games: {genre_id: @sort_attribute_2}).order("platformed_games.release_date DESC").page(@page).per(@limit)46 @user_games_next = current_user.user_games.joins(game: :genred_games).joins(game: :platformed_games).where(genred_games: {genre_id: @sort_attribute_2}).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)47 @user_games_next_2 = current_user.user_games.joins(game: :genred_games).joins(game: :platformed_games).where(genred_games: {genre_id: @sort_attribute_2}) .order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)48 elsif @filter == "release_date_asc"49 @user_games = current_user.user_games.joins(game: :genred_games).joins(game: :platformed_games).where(genred_games: {genre_id: @sort_attribute_2}).order("platformed_games.release_date ASC").page(@page).per(@limit)50 @user_games_next = current_user.user_games.joins(game: :genred_games).joins(game: :platformed_games).where(genred_games: {genre_id: @sort_attribute_2}).order("platformed_games.release_date ASC").page(@page.to_i + 1).per(@limit)51 @user_games_next_2 = current_user.user_games.joins(game: :genred_games).joins(game: :platformed_games).where(genred_games: {genre_id: @sort_attribute_2}).order("platformed_games.release_date ASC").page(@page.to_i + 2).per(@limit)52 else53 @user_games = current_user.user_games.joins(game: :genred_games).where(genred_games: {genre_id: @sort_attribute_2}).order(created_at: :desc).page(@page).per(@limit)54 @user_games_next = current_user.user_games.joins(game: :genred_games).where(genred_games: {genre_id: @sort_attribute_2}).order(created_at: :desc).page(@page.to_i + 1).per(@limit)55 @user_games_next_2 = current_user.user_games.joins(game: :genred_games).where(genred_games: {genre_id: @sort_attribute_2}) .order(created_at: :desc).page(@page.to_i + 2).per(@limit)56 end57 elsif @sort_attribute == "owned"58 if @filter == "name_up"59 @user_games = current_user.user_games.where(ownership: true).joins(:game).order("games.name").page(@page).per(@limit)60 @user_games_next = current_user.user_games.where(ownership: true).joins(:game).order("games.name").page(@page.to_i + 1).per(@limit)61 @user_games_next_2 = current_user.user_games.where(ownership: true).joins(:game).order("games.name").page(@page.to_i + 2).per(@limit)62 elsif @filter == "name_down"63 @user_games = current_user.user_games.where(ownership: true).joins(:game).order("games.name DESC").page(@page).per(@limit)64 @user_games_next = current_user.user_games.where(ownership: true).joins(:game).order("games.name DESC").page(@page.to_i + 1).per(@limit)65 @user_games_next_2 = current_user.user_games.where(ownership: true).joins(:game).order("games.name DESC").page(@page.to_i + 2).per(@limit)66 elsif @filter == "release_date_desc"67 @user_games = current_user.user_games.joins(game: :platformed_games).where(ownership: true).joins(:game).order("platformed_games.release_date DESC").page(@page).per(@limit)68 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(ownership: true).joins(:game).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)69 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(ownership: true).joins(:game).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)70 elsif @filter == "release_date_asc"71 @user_games = current_user.user_games.joins(game: :platformed_games).where(ownership: true).joins(:game).order("platformed_games.release_date ASC").page(@page).per(@limit)72 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(ownership: true).joins(:game).order("platformed_games.release_date ASC").page(@page.to_i + 1).per(@limit)73 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(ownership: true).joins(:game).order("platformed_games.release_date ASC").page(@page.to_i + 2).per(@limit)74 else75 @user_games = current_user.user_games.where(ownership: true).joins(:game).order(created_at: :desc).page(@page).per(@limit)76 @user_games_next = current_user.user_games.where(ownership: true).joins(:game).order(created_at: :desc).page(@page.to_i + 1).per(@limit)77 @user_games_next_2 = current_user.user_games.where(ownership: true).joins(:game).order(created_at: :desc).page(@page.to_i + 2).per(@limit)78 end79 elsif @sort_attribute == "wanted"80 if @filter == "name_up"81 @user_games = current_user.user_games.where(ownership: false).joins(:game).order("games.name").page(@page).per(@limit)82 @user_games_next = current_user.user_games.where(ownership: false).joins(:game).order("games.name").page(@page.to_i + 1).per(@limit)83 @user_games_next_2 = current_user.user_games.where(ownership: false).joins(:game).order("games.name").page(@page.to_i + 2).per(@limit)84 elsif @filter == "name_down"85 @user_games = current_user.user_games.where(ownership: false).joins(:game).order("games.name DESC").page(@page).per(@limit)86 @user_games_next = current_user.user_games.where(ownership: false).joins(:game).order("games.name DESC").page(@page.to_i + 1).per(@limit)87 @user_games_next_2 = current_user.user_games.where(ownership: false).joins(:game).order("games.name DESC").page(@page.to_i + 2).per(@limit)88 elsif @filter == "release_date_desc"89 @user_games = current_user.user_games.joins(game: :platformed_games).where(ownership: false).order("platformed_games.release_date DESC").page(@page).per(@limit)90 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(ownership: false).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)91 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(ownership: false).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)92 elsif @filter == "release_date_asc"93 @user_games = current_user.user_games.joins(game: :platformed_games).where(ownership: false).order("platformed_games.release_date ASC").page(@page).per(@limit)94 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(ownership: false).order("platformed_games.release_date ASC").page(@page.to_i + 1).per(@limit)95 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(ownership: false).order("platformed_games.release_date ASC").page(@page.to_i + 2).per(@limit)96 else97 @user_games = current_user.user_games.joins(game: :platformed_games).where(ownership: false).order("platformed_games.release_date DESC").page(@page).per(@limit)98 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(ownership: false).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)99 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(ownership: false).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)100 end101 elsif @filter == "name_up"102 @user_games = current_user.user_games.joins(:game).order(:ownership).order("games.name").page(@page).per(@limit)103 @user_games_next = current_user.user_games.joins(:game).order(:ownership).order("games.name").page(@page.to_i + 1).per(@limit)104 @user_games_next_2 = current_user.user_games.joins(:game).order(:ownership).order("games.name").page(@page.to_i + 2).per(@limit)105 elsif @filter == "name_down"106 @user_games = current_user.user_games.joins(:game).order(:ownership).order("games.name DESC").page(@page).per(@limit)107 @user_games_next = current_user.user_games.joins(:game).order(:ownership).order("games.name DESC").page(@page.to_i + 1).per(@limit)108 @user_games_next_2 = current_user.user_games.joins(:game).order(:ownership).order("games.name DESC").page(@page.to_i + 2).per(@limit)109 elsif @filter == "release_date_desc"110 @user_games = current_user.user_games.joins(game: :platformed_games).order("platformed_games.release_date DESC").page(@page).per(@limit)111 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)112 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)113 elsif @filter == "release_date_asc"114 @user_games = current_user.user_games.joins(game: :platformed_games).order("platformed_games.release_date ASC").page(@page).per(@limit)115 @user_games_next = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date ASC").page(@page.to_i + 1).per(@limit)116 @user_games_next_2 = current_user.user_games.joins(game: :platformed_games).where(platformed_games: {platform_id: @sort_attribute_2}).order("platformed_games.release_date ASC").page(@page.to_i + 2).per(@limit)117 else118 @user_games = current_user.user_games.order(:ownership).order(created_at: :desc).page(@page).per(@limit)119 @user_games_next = current_user.user_games.order(:ownership).order(created_at: :desc).page(@page.to_i + 1).per(@limit)120 @user_games_next_2 = current_user.user_games.order(:ownership).order(created_at: :desc).page(@page.to_i + 2).per(@limit)121 end122 if current_user.user_games.any? 123 @sample_game = @user_games.sample124 counter = 0125 until @sample_game.game.game_covers.any?126 @sample_game = @user_games.sample127 counter += 1128 if counter > 5129 break130 end131 end132 @platforms = []133 @genres = []134 current_user.user_games.each do |user_game|135 user_game.game.platformed_games.each do |platformed_game|136 if !@platforms.include?(Platform.find_by(id: platformed_game.platform_id))137 @platforms << Platform.find_by(id: platformed_game.platform_id)138 end139 end140 user_game.game.genred_games.each do |genred_game|141 if !@genres.include?(Genre.find_by(id: genred_game.genre_id))142 @genres << Genre.find_by(id: genred_game.genre_id)143 end144 end145 end146 end147 @users_page = 0148 end149 def create150 game_id_list = []151 current_user.user_games.each do |user_game|152 game_id_list << user_game.game_id153 end154 if !game_id_list.include?(params[:game_id])155 user_game = UserGame.new(156 game_id: params[:game_id],157 user_id: current_user.id,158 ownership: false159 )160 if user_game.save161 Game.find_by(id: params[:game_id]).genred_games.each do |genred_game|162 user_genre = UserGenre.create(163 game_id: params[:game_id],164 user_id: current_user.id,165 genre_id: genred_game.genre_id166 )167 end168 flash[:success] = "#{Game.find_by(id: params[:game_id]).name} added to your list!"169 redirect_to '/user_games'170 else171 flash[:danger] = "Error"172 redirect_to "games/#{params[:game_id]}"173 end174 else175 flash[:danger] = "Game is already on your list!"176 redirect_to '/user_games' 177 178 end179 end180 def update181 user_game = UserGame.find_by(id: params[:id])182 user_game.assign_attributes(183 ownership: !user_game.ownership184 )185 if user_game.save186 flash[:success] = "#{Game.find_by(id: user_game.game_id).name} ownership status changed on your list!"187 redirect_to '/user_games'188 else189 flash[:danger] = "Error!"190 redirect_to '/user_games'191 end192 end193 def destroy194 user_game = UserGame.find_by(id: params[:id])195 user_genres = UserGame.find_by(id: params[:id]).game.user_genres.where(user_id: current_user.id)196 user_genres.each do |user_genre|197 user_genre.destroy198 end199 user_game.destroy200 flash[:success] = "Game removed from list"201 redirect_to "/user_games"202 end203end...
games_controller.rb
Source:games_controller.rb
...13 @sort_attribute = params[:sort_attribute]14 @sort_attribute_2 = params[:sort_attribute_2]15 @filter = params[:filter]16 if !@search.empty?17 @games = Game.where("name ILIKE ?", "%#{params[:search]}%").order(:name).page(@page).per(@limit)18 @games_next = Game.where("name ILIKE ?", "%#{params[:search]}%").order(:name).page(@page.to_i + 1).per(@limit)19 @games_next_2 = Game.where("name ILIKE ?", "%#{params[:search]}%").order(:name).page(@page.to_i + 2).per(@limit)20 elsif @sort_attribute == "platform"21 if @filter == "name_up"22 @games = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order(:name).page(@page).per(@limit)23 @games_next = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order(:name).page(@page.to_i + 1).per(@limit)24 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order(:name).page(@page.to_i + 2).per(@limit)25 elsif @filter == "name_down"26 @games = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order(name: :desc).page(@page).per(@limit)27 @games_next = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order(name: :desc).page(@page.to_i + 1).per(@limit)28 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order(name: :desc).page(@page.to_i + 2).per(@limit)29 elsif @filter == "release_date_desc"30 @games = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page).per(@limit)31 @games_next = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)32 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)33 elsif @filter == "release_date_asc"34 @games = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date ASC").page(@page).per(@limit)35 @games_next = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date ASC").page(@page.to_i + 1).per(@limit)36 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date ASC").page(@page.to_i + 2).per(@limit)37 else38 @games = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page).per(@limit)39 @games_next = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)40 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.platform_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)41 end42 elsif @sort_attribute == "genre"43 if @filter == "name_up"44 @games = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order(:name).page(@page).per(@limit)45 @games_next = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order(:name).page(@page.to_i + 1).per(@limit)46 @games_next_2 = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order(:name).page(@page.to_i + 2).per(@limit)47 elsif @filter == "name_down"48 @games = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order(name: :desc).page(@page).per(@limit)49 @games_next = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order(name: :desc).page(@page.to_i + 1).per(@limit)50 @games_next_2 = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order(name: :desc).page(@page.to_i + 2).per(@limit)51 elsif @filter == "release_date_desc"52 @games = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order("platformed_games.release_date DESC").page(@page).per(@limit)53 @games_next = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)54 @games_next_2 = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)55 elsif @filter == "release_date_asc"56 @games = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order("platformed_games.release_date ASC").page(@page).per(@limit)57 @games_next = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order("platformed_games.release_date ASC").page(@page.to_i + 1).per(@limit)58 @games_next_2 = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order("platformed_games.release_date ASC").page(@page.to_i + 2).per(@limit)59 else60 @games = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order("platformed_games.release_date DESC").page(@page).per(@limit)61 @games_next = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)62 @games_next_2 = Game.includes(:genred_games, :platformed_games).where("genred_games.genre_id = #{@sort_attribute_2}").where("platformed_games.id >= 0").references(:genred_games, :platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)63 end64 elsif @filter == "name_up"65 @games = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order(:name).page(@page).per(@limit)66 @games_next = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order(:name).page(@page.to_i + 1).per(@limit)67 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order(:name).page(@page.to_i + 2).per(@limit)68 elsif @filter == "name_down"69 @games = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order(name: :desc).page(@page).per(@limit)70 @games_next = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order(name: :desc).page(@page.to_i + 1).per(@limit)71 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order(name: :desc).page(@page.to_i + 2).per(@limit)72 elsif @filter == "release_date_desc"73 @games = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page).per(@limit)74 @games_next = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)75 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)76 elsif @filter == "release_date_asc"77 @games = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date ASC").page(@page).per(@limit)78 @games_next = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date ASC").page(@page.to_i + 1).per(@limit)79 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date ASC").page(@page.to_i + 2).per(@limit)80 else81 @games = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page).per(@limit)82 @games_next = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 1).per(@limit)83 @games_next_2 = Game.includes(:platformed_games).where("platformed_games.id >= 0").references(:platformed_games).order("platformed_games.release_date DESC").page(@page.to_i + 2).per(@limit)84 end85 @platforms_1 = Platform.where.not(release_date: nil).order(release_date: :desc)86 @platforms_2 = Platform.where(release_date: nil).order(:name)87 @platforms = @platforms_1 | @platforms_288 @genres = Genre.all.order(:name)89 if @games.any?90 @sample_games = []91 index = 0 92 counter = 093 until @sample_games.length >= 294 sample = @games.includes(:game_covers).where("game_covers.id >= 0").references(:game_covers).sample95 if !@sample_games.include?(sample) && sample.game_covers96 @sample_games << sample97 index += 198 counter = 099 end100 counter += 1101 if counter == 5102 break103 end104 end105 end106 end107 def index_2108 @counter = 0109 sort_attribute= params[:sort_attribute]110 sort_attribute_2 = params[:sort_attribute_2]111 if sort_attribute == "platform"112 @games = Game.includes(:platformed_games).where("platformed_games.platform_id = #{sort_attribute_2}").references(:platformed_games).order(:name)113 # if sort_attribute_2 == "1"114 # @games = Game.includes(:platformed_games).where('platformed_games.platform_id = 1').references(:platformed_games).order(:name) #ps4115 # elsif sort_attribute_2 == "2"116 # @games = Game.includes(:platformed_games).where('platformed_games.platform_id = 2').references(:platformed_games).order(:name) #xbone117 # elsif sort_attribute_2 == "3"118 # @games = Game.includes(:platformed_games).where('platformed_games.platform_id = 3').references(:platformed_games).order(:name) #wii u119 # elsif sort_attribute_2 == "4"120 # @games = Game.includes(:platformed_games).where('platformed_games.platform_id = 4').references(:platformed_games).order(:name) #pc121 # end122 elsif sort_attribute == "genre"123 @games = Game.includes(:genred_games).where("genred_games.genre_id = #{sort_attribute_2}").references(:genred_games).order(:name)124 # if sort_attribute_2 == "1"125 # @games = Game.includes(:genred_games).where('genred_games.genre_id = 1').references(:genred_games).order(:name) #action-rpg126 # elsif sort_attribute_2 == "2"127 # @games = Game.includes(:genred_games).where('genred_games.genre_id = 2').references(:genred_games).order(:name) #fps128 # elsif sort_attribute_2 == "3"129 # @games = Game.includes(:genred_games).where('genred_games.genre_id = 3').references(:genred_games).order(:name) #survival-horror130 # elsif sort_attribute_2 == "4"131 # @games = Game.includes(:genred_games).where('genred_games.genre_id = 4').references(:genred_games).order(:name) #action-rpg132 # end133 else134 @games = Game.where("name LIKE ?", "%Metal Gear Solid%").order(:name).limit(15)135 end136 end137 def show138 @game = Game.find_by(id: params[:id])139 @game_images = []140 if @game.game_covers.any?141 @game_images << @game.game_covers.first142 end143 if @game.game_screenshots.any?144 @game.game_screenshots.each do |screenshot|145 @game_images << screenshot146 end147 end148 @index = 0...
product_category_controller.rb
Source:product_category_controller.rb
1class ProductCategoryController < ApplicationController2 def index3 # @product_category = ProductCategory.find(params[:product_category_id])4 # @product_category.punch(request)5 @best_seller_products = Product.where( status: true).limit(5)6 # @products = Product.where(product_category_id: params[:product_category_id]).paginate(page: params[:page], per_page: 21)7 if params[:category].present? && params[:type].present?8 query_1 = "%#{params[:type].gsub("_", " ")}%"9 @category = Category.where("title ILIKE ?", query_1).first10 @product_categories = @category.product_categories11 query = "%#{params[:category].gsub("_", " ")}%"12 @product_category = ProductCategory.where("title ILIKE ?", query)13 if @product_category.count == 114 @products = Product.where(product_category_id: @product_category.last.id, status: true)15 else16 @products = Product.where(product_category_id: @product_category.pluck(:id), status: true)17 end18 @brand_products = @products19 @companies = Company.where(id: @products.pluck(:company_id))20 if params[:brand].present?21 query = "%#{params[:brand].gsub("_", " ")}%"22 @brand = Company.where("title ILIKE ?", query).first23 @products = @products.where(company_id: @brand.id)24 end25 if params[:search].present?26 @products = @products.where("print_description ILIKE '%#{params[:search]}%'")27 end28 if params[:min_val].present? && params[:max_val].present?29 @products = @products.where(:price => (params[:min_val].to_f..params[:max_val].to_f))30 end31 if params[:sort_by].present?32 if params[:sort_by] == "Price (low to high)"33 @products = @products.order("price ASC")34 elsif params[:sort_by] == "Price (high to low)"35 @products = @products.order("price DESC")36 elsif params[:sort_by] == "Newest"37 @products = @products.order("created_at DESC")38 end39 else40 @products = @products.order("price ASC")41 end42 if request.xhr?43 render partial: "products"44 end45 elsif params[:type].present?46 query = "%#{params[:type].gsub("_", " ")}%"47 @category = Category.where("title ILIKE ?", query).first48 @product_categories = @category.product_categories49 product_category_ids = []50 @product_categories.each do |product_category|51 @product_cats = ProductCategory.where(title: product_category.title)52 @product_cats.each do |product_cat|53 product_category_ids << product_cat.id54 end55 end56 @products = Product.where(product_category_id: product_category_ids, status: true)57 @brand_products = @products58 @companies = Company.where(id: @products.pluck(:company_id))59 if params[:brand].present?60 query = "%#{params[:brand].gsub("_", " ")}%"61 @brand = Company.where("title ILIKE ?", query).first62 @products = @products.where(company_id: @brand.id)63 end64 if params[:search].present?65 @products = @products.where("print_description ILIKE '%#{params[:search]}%'")66 end67 if params[:min_val].present? && params[:max_val].present?68 @products = @products.where(:price => (params[:min_val].to_f..params[:max_val].to_f))69 end70 if params[:sort_by].present?71 if params[:sort_by] == "Price (low to high)"72 @products = @products.order("price ASC")73 elsif params[:sort_by] == "Price (high to low)"74 @products = @products.order("price DESC")75 elsif params[:sort_by] == "Newest"76 @products = @products.order("created_at DESC")77 end78 else79 @products = @products.order("price ASC")80 end81 @products = @products.where(status: true)82 if request.format.html? == nil83 render partial: "products"84 end85 # //////////for sorting//////////// 86 elsif (params[:sort_by].present? || params[:search_query].present? || params[:search_query].present?) && params[:category].blank? && params[:type].blank?87 if params[:search_query].present?88 @products = Product.where("print_description ILIKE '%#{params[:search_query]}%' AND status = true")89 else90 @products = Product.where(status: true)91 end92 if params[:sort_by].present?93 if params[:sort_by] == "Price (low to high)"94 @products = @products.order("price ASC")95 elsif params[:sort_by] == "Price (high to low)"96 @products = @products.order("price DESC")97 elsif params[:sort_by] == "Newest"98 @products = @products.order("created_at DESC")99 end100 else101 @products = @products.order("price ASC")102 end103 if params[:search].present?104 @products = @products.where("print_description ILIKE '%#{params[:search]}%'")105 end106 if params[:min_val].present? && params[:max_val].present?107 @products = @products.where(:price => (params[:min_val].to_f..params[:max_val].to_f))108 end109 if request.xhr?110 render partial: "products"111 end112 #////////end/////////113 else114 if params[:search_query].present?115 @products = Product.where("print_description ILIKE '%#{params[:search_query]}%' AND status = true")116 else117 @products = Product.where(status: true)118 end119 if params[:sort_by].present?120 if params[:sort_by] == "Price (low to high)"121 @products = @products.order("price ASC")122 elsif params[:sort_by] == "Price (high to low)"123 @products = @products.order("price DESC")124 elsif params[:sort_by] == "Newest"125 @products = @products.order("created_at DESC")126 end127 else128 @products = @products.order("price ASC")129 end130 if request.xhr?131 render partial: "products"132 end133 end134 end135 def brand_products136 @best_seller_products = Product.where( status: true).limit(5)137 if params[:brand].present?138 query = "%#{params[:brand].gsub("_", " ")}%"139 @brand = Company.where("title ILIKE ?", query).first140 @products = @brand.products141 @brand_products = @products142 @product_categories = ProductCategory.where(id: @products.pluck(:product_category_id))143 @category = Category.where(id: @product_categories.pluck(:category_id)).first144 @companies = Company.where(id: @products.pluck(:company_id))145 if params[:brand].present?146 query = "%#{params[:brand].gsub("_", " ")}%"147 @brand = Company.where("title ILIKE ?", query).first148 @products = @products.where(company_id: @brand.id)149 end150 if params[:category].present?151 query = "%#{params[:category].gsub("_", " ")}%"152 @product_category = ProductCategory.where("title ILIKE ?", query).first153 @products = @products.where(product_category_id: @product_category.id)154 end155 if params[:search].present?156 @products = @products.where("print_description ILIKE '%#{params[:search]}%'")157 end158 if params[:sort_by].present?159 if params[:sort_by] == "Price(low to high)"160 @products = @products.order("price ASC")161 elsif params[:sort_by] == "Price(high to low)"162 @products = @products.order("price DESC")163 else164 @products = @products.order("#{params[:sort_by]} DESC")165 end166 end167 end168 end169end...
where
Using AI Code Generation
1 return enum_for(:my_each) unless block_given?2 yield(self[i])3 return enum_for(:my_each_with_index) unless block_given?4 yield(self[i], i)5 return enum_for(:my_select) unless block_given?6 my_each { |x| arr << x if yield(x) }7 def my_all?(arg = nil)8 my_each { |x| return false unless yield(x) }9 my_each { |x| return false unless x }10 elsif arg.is_a?(Regexp)11 my_each { |x| return false unless x.match(arg) }12 elsif arg.is_a?(Class)13 my_each { |x| return false unless x.is_a?(arg) }14 my_each { |x| return false unless x == arg }15 def my_any?(arg = nil)16 my_each { |x| return true if yield(x) }17 my_each { |x| return true if x }18 elsif arg.is_a?(Regexp)19 my_each { |x| return true if x.match(arg) }20 elsif arg.is_a?(Class)21 my_each { |x| return true if x.is_a?(arg) }22 my_each { |x| return true if x == arg }23 def my_none?(arg = nil)24 my_each { |x| return false if yield(x) }25 my_each { |x| return false if x }26 elsif arg.is_a?(Regexp)27 my_each { |x| return false if x.match(arg) }28 elsif arg.is_a?(Class)29 my_each { |x| return false if x.is_a?(arg) }30 my_each { |
where
Using AI Code Generation
1sort.where(2, 3, 1, 5, 4, 8, 7, 6)2sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9)3sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10)4sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11)5sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12)6sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13)7sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14)8sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14, 15)9sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14, 15, 16)10sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17)11sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)12sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12
where
Using AI Code Generation
1sort_object.where("name", "like", "A%")2 def where(column, operator, value)31.rb:3:in `require': cannot load such file -- ./sort.rb (LoadError)4sort_object.where("name", "like", "A%")5 def where(column, operator, value)61.rb:3:in `require': cannot load such file -- ./sort.rb (LoadError)7sort_object.where("name", "like", "A%")8 def where(column, operator, value)91.rb:3:in `require': cannot load such file -- ./sort.rb (LoadError)
where
Using AI Code Generation
1sort.where(2, 3, 1, 5, 4, 8, 7, 6)2sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9)3sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10)4sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11)5sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12)6sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13)7sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14)8sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14, 15)9sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14, 15, 16)10sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17)11sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)12sort.where(2, 3, 1, 5, 4, 8, 7, 6, 9, 10, 11, 12
where
Using AI Code Generation
1sort_object.where("name", "like", "A%")2 def where(column, operator, value)31.rb:3:in `require': cannot load such file -- ./sort.rb (LoadError)4sort_object.where("name", "like", "A%")5 def where(column, operator, value)61.rb:3:in `require': cannot load such file -- ./sort.rb (LoadError)7sort_object.where("name", "like", "A%")8 def where(column, operator, value)91.rb:3:in `require': cannot load such file -- ./sort.rb (LoadError)
where
Using AI Code Generation
1sort_object.where("name", "like", "A%")2 def where(column, operator, value)31.rb:3:in `require': cannot load such file -- ./sort.rb (LoadError)4sort_object.where("name", "like", "A%")5 def where(column, operator, value)61.rb:3:in `require': cannot load such file -- ./sort.rb (LoadError)7sort_object.where("name", "like", "A%")8 def where(column, operator, value)91.rb:3:in `require': cannot load such file -- ./sort.rb (LoadError)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!