0

Im haveing problems with seeing the attachments from plugin, it shows me the message : You are not authorized to access this page. I used the attachments helper to upload things in my plugin. Here is the code: Init.rb(giving permissions)

project_module :plugin_name do

permission :view_attachments, :attachments => [:show, :download, :thumbnail, :upload]

The model class, in my case Unit.rb

class Unit < ActiveRecord::Base
    belongs_to :project


     acts_as_attachable :view_permission => :view_attachments

units_controller.rb

class UnitsController < ApplicationController 

  helper :attachments
  include AttachmentsHelper     
  menu_item :overviews, :only => [:index, :show, :edit, :new, :update, :create]
  before_filter(:find_project, :authorize, :only => [:index, :show, :edit, :new, :update, :create])

...
def create
    @unit = Unit.new(unit_params)
      if(@unit.save)
      attachments = Attachment.attach_files(@unit, params[:attachments])
   redirect_to(:action => "index")
    flash[:notice] = l(:createMessage)
      else
          render("new")
      end
  end

units show.html.erb

<%= link_to_attachments @unit  %>

P.S- when i remove this part of code in attachments_controller then i can see my attachments, see below:

before_filter :file_readable, :read_authorize, :only => [:show, :download, :thumbnail]

read_authorize action:

def read_authorize
    @attachment.visible? ? true : deny_access
  end
ILLYRIUM
  • 9
  • 2

1 Answers1

0

I think, you should not reinit permission for attachments. Try to use special permission from Unit:

acts_as_attachable :view_permission => :view_unit

kunashir
  • 917
  • 8
  • 21
  • i tried that but it doesnt work, i made them all :public => true but still doesnt give me permission to attachments – ILLYRIUM Apr 25 '16 at 07:12