Main Avalanche Network server application. Built with Ruby on Rails.

rewards_controller.rb 2.2KB

    class MissionEditor::RewardsController < ApplicationController before_action :set_reward, only: [:edit, :update, :destroy] before_action :set_mission # GET /rewards # GET /rewards.json def index @rewards = Reward.where(mission: @mission) end # GET /rewards/new def new @reward = Reward.new end # GET /rewards/1/edit def edit end # POST /rewards # POST /rewards.json def create @reward = Reward.new(reward_params) @reward.mission = @mission respond_to do |format| if @reward.save format.html { redirect_to rewards_path, notice: 'Reward was successfully created.' } format.json { render action: 'show', status: :created, location: @reward } else format.html { render action: 'new' } format.json { render json: @reward.errors, status: :unprocessable_entity } end end end # PATCH/PUT /rewards/1 # PATCH/PUT /rewards/1.json def update @reward.mission = @mission agents = params[:reward][:mission_agents] @reward.mission_agents = [] agents.each do |a| if a != "" agent = MissionAgent.find(a.to_i) @reward.mission_agents << agent end end respond_to do |format| if @reward.update(reward_params) format.html { redirect_to rewards_path, notice: 'Reward was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @reward.errors, status: :unprocessable_entity } end end end # DELETE /rewards/1 # DELETE /rewards/1.json def destroy @reward.destroy respond_to do |format| format.html { redirect_to rewards_url } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_reward @reward = Reward.find(params[:id]) end def set_mission @mission = Mission.friendly.find(params[:mission]) end # Never trust parameters from the scary internet, only allow the white list through. def reward_params params.require(:reward).permit(:title, :description, :img, :mission_agents) end end