diff options
| author | Luc Donnet | 2017-07-13 15:34:41 +0200 | 
|---|---|---|
| committer | Luc Donnet | 2017-07-13 15:34:41 +0200 | 
| commit | 8d342e0402d0f4b858c77469ca01f428a45503f0 (patch) | |
| tree | 6ee0f9ac6211b8b6f057b6f05f9de3626509541a /app/controllers/line_footnotes_controller.rb | |
| parent | bc33eba0f1129a491a56bc9b616f388477489b0b (diff) | |
| download | chouette-core-8d342e0402d0f4b858c77469ca01f428a45503f0.tar.bz2 | |
Fix footnotes policy Refs #4094 @2
Diffstat (limited to 'app/controllers/line_footnotes_controller.rb')
| -rw-r--r-- | app/controllers/line_footnotes_controller.rb | 29 | 
1 files changed, 11 insertions, 18 deletions
| diff --git a/app/controllers/line_footnotes_controller.rb b/app/controllers/line_footnotes_controller.rb index 6a9048392..f24d624d4 100644 --- a/app/controllers/line_footnotes_controller.rb +++ b/app/controllers/line_footnotes_controller.rb @@ -1,16 +1,7 @@ -class LineFootnotesController < BreadcrumbController -  defaults :resource_class => Chouette::Line -  include PolicyChecker -  respond_to :json, :only => :show +class LineFootnotesController < ChouetteController +  defaults resource_class: Chouette::Line, collection_name: 'lines', instance_name: 'line'    belongs_to :referential -  def show -    show! do -      build_breadcrumb :show -    end -    @footnotes = @line.footnotes -  end -    def edit      edit! do        build_breadcrumb :edit @@ -18,25 +9,27 @@ class LineFootnotesController < BreadcrumbController    end    def update -    if @line.update(line_params) -      redirect_to referential_line_footnotes_path(@referential, @line) , notice: t('notice.footnotes.updated') -    else -      render :edit +    update! do |success, failure| +      success.html { redirect_to referential_line_footnotes_path(@referential, @line) , notice: t('notice.footnotes.updated') } +      failure.html { render :edit }      end    end    protected + +  alias_method :line, :resource +    # overrides default    def check_policy      authorize resource, "#{action_name}_footnote?".to_sym    end -  private    def resource -    @referential = Referential.find params[:referential_id] -    @line        = @referential.lines.find params[:line_id] +    @line ||= current_referential.lines.find params[:line_id]    end +  private +    def line_params      params.require(:line).permit(        { footnotes_attributes: [ :code, :label, :_destroy, :id ] } ) | 
