class DotationsController < ApplicationController include ApplicationHelper before_action :check_access before_action :set_dotation, only: %i[show edit update destroy activate] # GET /dotations or /dotations.json def index @dotations = Dotation.search(params[:search]).order(:name).page(params[:page]).per(2) end def check_access redirect_to not_found unless role?('dotations') end # GET /dotations/1 or /dotations/1.json def show @company_sizes = CompanySize.all end # GET /dotations/new def new @dotation = Dotation.new prepare_dependencies end # GET /dotations/1/edit def edit prepare_dependencies end def activate @dotation.active = if @dotation.active.eql?(false) true else false end @dotation.save end # POST /dotations or /dotations.json def create @dotation = Dotation.new(dotation_params) prepare_dependencies respond_to do |format| if @dotation.save format.html { redirect_to dotations_url, notice: 'Utworzono pomyślnie.' } format.json { render :show, status: :created, location: @dotation } else format.html { render :new, status: :unprocessable_entity } format.json { render json: @dotation.errors, status: :unprocessable_entity } end end end # PATCH/PUT /dotations/1 or /dotations/1.json def update prepare_dependencies respond_to do |format| if @dotation.update(dotation_params) format.html { redirect_to dotations_url, notice: 'Zaktualizowano pomyślnie.' } format.json { render :show, status: :ok, location: @dotation } else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @dotation.errors, status: :unprocessable_entity } end end end # DELETE /dotations/1 or /dotations/1.json def destroy @dotation.destroy respond_to do |format| format.html { redirect_to dotations_url, notice: 'Usunięto pomyślnie.' } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_dotation @dotation = Dotation.find(params[:id]) end def prepare_dependencies @currencies = Currency.all @company_sizes = CompanySize.all @company_activities = CompanyActivity.all @tags = Tag.all @projects = Project.all @experts = Expert.all @expenses = Expense.all @partners = Partner.all end # Only allow a list of trusted parameters through. def dotation_params params.require(:dotation) .permit(:name, :formal_name, :date_from, :date_to, :min_amount, :max_amount, :max_percent, :localization, :company_size_id, :partner_id, :expert_id, :expert_info, :start_date, :end_date, :announcement_date, :full_descr, :positioning_text, :points, :date_of_recruitment, :min_amount_curr_id, :max_amount_curr_id, project_ids: [], tag_ids: [], company_activity_ids: [], company_size_ids: []) end end