ruby on rails - How to distribute uploaded files to Users attributes? -
okay, i'm little new @ this; don't know how go doing this:
i have assets model, articles model, , user model.
the assets model has paperclip document attribute.
#asset.rb belongs_to :article has_attached_file :document, :path => "assets/:id-:basename-:style.:extension", storage: :dropbox, dropbox_credentials: rails.root.join("config/dropbox.yml") validates_attachment :document, content_type: { content_type: "application/pdf" } #article.rb belongs_to :user has_many :assets, dependent: :destroy accepts_nested_attributes_for :assets, allow_destroy: true, :reject_if => lambda { |d| d[:document].blank? } validates :title, :content, presence: true #articles_controller.rb def new @article = article.new @article.assets.build end def article_params params.require(:article).permit(:title, :content, assets_attributes: [:id, :article_id, :document, :_destroy] ) end #user.rb has_many :articles, dependent: :destroy has_many :assets, through: :articles regex_email = /\a([\w+\-.]+)(@[\w+\-.]+)(\.[a-z]+)\z/i validates :email, format: { with: regex_email }, uniqueness: { case_sensitive: false } validates :password, length: { minimum: 6 } has_secure_password validates :dp_key, :dp_secret, presence: true #config/dropbox.yml app_key: "r3g00ca3v1hfwjj" app_secret: "dkixp9rgqkkyflma" access_token: "13dn69hab311ij35" access_token_secret: "hq1jniuyjpa791y" user_id: "14864638" access_type: "app_folder"
each user has attribute dropbox apikey. want whenever upload document asset, want asset model use user's api key rather default 1 if user doesn't have saved drop apikey.
i assuming need pass variables controller model?
any appreciated, thanks!
Comments
Post a Comment