在我的模型中:
has_attached_file :uploaded_file,
:url => "/policy_documents/get/:id",
:path => "/public/policy_documents/:id/:basename.:extension"
validates_attachment_size :uploaded_file, :less_than => 10.megabytes
validates_attachment_presence :uploaded_file
validates_attachment_content_type :uploaded_file, :content_type =>['application/pdf', 'application/xlsx'],
:message => ', Only PDF, EXCEL, WORD or TEXT files are allowed. '
Run Code Online (Sandbox Code Playgroud)
在此之后,它只能上传PDF文档,而不是excel或文字或文本文档.请帮助我,我失踪了!
我知道这是一个愚蠢的但我想知道我们如何创建一个current_user方法来获取整个应用程序的访问权限而不使用任何gem或插件?为了测试它我创建了一个应用程序,使用户能够共享文件和文件夹.如何创建这样的方法,用户只能访问他的文件夹和文件?这是我的代码示例:
登录控制器:
class LoginController < ApplicationController
layout 'signup'
#to skip checking the authentication and authorization.
skip_before_filter :check_authentication, :check_authorization
def index
end
def authenticate
if request.post?
user = User.authenticate(params[:username],params[:password])
if user
session[:current_user_id]=user.id
session[:name]= user.first_name
puts "session name #{session[:name]}"
redirect_to(:subdomain => user.company.subdomain, :controller => :dashboard)
else
flash.now[:notice] = "Invalid user/password combination"
end
end
end
def destroy
session[:current_user_id] = nil
reset_session
flash[:notice] = "You have been successfully logged out."
redirect_to root_url
end
end
Run Code Online (Sandbox Code Playgroud)
用户模型:
require 'digest/sha1'
class User < ActiveRecord::Base
#sharering method start …Run Code Online (Sandbox Code Playgroud)