Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BasicInformationsController < ApplicationController
- before_action :set_basic_information, only: [:show, :edit, :update]
- before_action :set_filiations, only: [:show, :edit, :update]
- before_action :set_founders, only: [:show, :edit, :update]
- before_action :authenticate_user!
- skip_before_action :verify_authenticity_token
- # GET /basic_informations/new
- def new
- @basic_information = BasicInformation.new
- end
- # GET /basic_informations/1/edit
- def edit
- end
- def destroy
- if params["fl_id"].present?
- Filiation.find(params["fl_id"]).destroy
- end
- if params["fn_id"].present?
- Founder.find(params["fn_id"]).destroy
- end
- redirect_back(fallback_location: root_path)
- end
- def index
- @basic_informations = BasicInformation.all
- end
- # POST /basic_informations
- def create
- if params["create"]=="fil"
- @filiation = Filiation.new(:'owner' => current_user.id)
- @filiation.save
- end
- if params["create"]=="found"
- @founder = Founder.new(:'owner' => current_user.id)
- @founder.save
- end
- redirect_back(fallback_location: root_path)
- end
- # PATCH/PUT /basic_informations/1
- def update
- founder_params_update
- filiation_params_update
- @basic_information.update(basic_information_params)
- #redirect_to root_path(notice: 'information was successfully created.')
- end
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_basic_information
- @basic_information = BasicInformation.last
- end
- def set_filiations
- @filiations_list = []
- Filiation.all.each do |f|
- @filiations_list << f
- end
- end
- def set_founders
- @founders_list = []
- Founder.all.each do |f|
- @founders_list << f
- end
- end
- # Never trust parameters from the scary internet, only allow the white list through.
- def basic_information_params
- params.require(:basic_information).permit!
- end
- def filiation_params_update
- if params["filiations"].present?
- params["filiations"].each do |filiation|
- if params["filiations"][filiation]["name"] != ""
- @params = params["filiations"][filiation].permit!
- @params["owner"] = current_user.id
- Filiation.find(filiation).update(@params)
- end
- end
- end
- end
- def founder_params_update
- if params["founders"].present?
- params["founders"].each do |founder|
- @params = params["founders"][founder].permit!
- @params["owner"] = current_user.id
- Founder.find(founder).update(@params)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment