diff --git a/app/controllers/mezuro_configurations_controller.rb b/app/controllers/mezuro_configurations_controller.rb index 595d317..fa8bff0 100644 --- a/app/controllers/mezuro_configurations_controller.rb +++ b/app/controllers/mezuro_configurations_controller.rb @@ -1,25 +1,24 @@ include OwnershipAuthentication class MezuroConfigurationsController < ApplicationController - before_action :authenticate_user!, - except: [:index, :show] + before_action :authenticate_user!, except: [:index, :show] before_action :mezuro_configuration_owner?, only: [:edit, :update, :destroy] # GET /mezuro_configurations/new def new - @mezuro_configuration = MezuroConfiguration.new + @configuration = MezuroConfiguration.new end # GET /mezuro_configurations # GET /mezuro_configurations.json def index - @mezuro_configurations = MezuroConfiguration.all + @configurations = MezuroConfiguration.all end # POST /mezuro_configurations # POST /mezuro_configurations.json def create - @mezuro_configuration = MezuroConfiguration.new(mezuro_configuration_params) + @configuration = MezuroConfiguration.new(mezuro_configuration_params) respond_to do |format| create_and_redir(format) end @@ -29,7 +28,7 @@ class MezuroConfigurationsController < ApplicationController # GET /mezuro_configurations/1.json def show set_mezuro_configuration - @mezuro_configuration_metric_configurations = @mezuro_configuration.metric_configurations + @configuration_metric_configurations = @configuration.metric_configurations end # GET /mezuro_configurations/1/edit @@ -41,8 +40,8 @@ class MezuroConfigurationsController < ApplicationController def update set_mezuro_configuration - if @mezuro_configuration.update(mezuro_configuration_params) - redirect_to(mezuro_configuration_path(@mezuro_configuration.id)) + if @configuration.update(mezuro_configuration_params) + redirect_to(mezuro_configuration_path(@configuration.id)) else render "edit" end @@ -52,8 +51,8 @@ class MezuroConfigurationsController < ApplicationController # DELETE /mezuro_configurations/1.json def destroy set_mezuro_configuration - current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(@mezuro_configuration.id).destroy - @mezuro_configuration.destroy + current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(@configuration.id).destroy + @configuration.destroy respond_to do |format| format.html { redirect_to mezuro_configurations_url } format.json { head :no_content } @@ -63,7 +62,7 @@ class MezuroConfigurationsController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_mezuro_configuration - @mezuro_configuration = MezuroConfiguration.find(params[:id]) + @configuration = MezuroConfiguration.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. @@ -73,14 +72,14 @@ class MezuroConfigurationsController < ApplicationController # Extracted code from create action def create_and_redir(format) - if @mezuro_configuration.save - current_user.mezuro_configuration_ownerships.create mezuro_configuration_id: @mezuro_configuration.id + if @configuration.save + current_user.mezuro_configuration_ownerships.create mezuro_configuration_id: @configuration.id - format.html { redirect_to mezuro_configuration_path(@mezuro_configuration.id), notice: 'mezuro_configuration was successfully created.' } - format.json { render action: 'show', status: :created, location: @mezuro_configuration } + format.html { redirect_to mezuro_configuration_path(@configuration.id), notice: 'mezuro_configuration was successfully created.' } + format.json { render action: 'show', status: :created, location: @configuration } else format.html { render action: 'new' } - format.json { render json: @mezuro_configuration.errors, status: :unprocessable_entity } + format.json { render json: @configuration.errors, status: :unprocessable_entity } end end end diff --git a/app/helpers/mezuro_configurations_helper.rb b/app/helpers/mezuro_configurations_helper.rb new file mode 100644 index 0000000..fa66301 --- /dev/null +++ b/app/helpers/mezuro_configurations_helper.rb @@ -0,0 +1,5 @@ +module MezuroConfigurationsHelper + def configuration_owner?(configuration_id) + user_signed_in? && !current_user.mezuro_configuration_ownerships.find_by_mezuro_configuration_id(configuration_id).nil? + end +end \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f4fe471..a08ae2c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -59,6 +59,7 @@