原始名称只是用来显示,网站自定义名称用来存储,然后配对使用。 其中一个问题就是原始文件名容易重复,那就不好办了。 还有其他的,请补充!
第一个办法,我刚才试验过了,行得通。
当然了,还有第三个,直接使用第三方的 authentication,例如 devise
我想出来几个办法。 1.在 validates 后面加上个:if => Proc.new { |u| u.new_record? },然后修改密码,自己写 sql 执行。 2.更新用户和修改密码都自己写 sql 执行,还可以控制的很好。
下面这个就会验证 password,就算加上 delete(:password) 也没有用。
def update
@user=User.find(params[:id])
params[:user].delete(:password)
params[:user].delete(:password_confirmatin)
if @user.update_attributes(params[:user])
flash[:notice]="-update user successful"
redirect_to @user
else
flash.now[:notice]="-update user fail"
render :edit
end
end
def update
@user=User.find(params[:id])
@user.email=params[:user][:email]
@user.username=params[:user][:username]
if @user.update_attribute(:username, params[:user][:username])
flash[:notice]="-update user successful"
redirect_to @user
else
flash.now[:notice]="-update user fail"
render :edit
end
end
require 'digest'
class User < ActiveRecord::Base
attr_accessor :password, :password_confirmation
attr_accessible :username, :email, :password, :password_confirmation
# has_secure_password
validates :username, :presence => true, :length => { :in =>6..20 }, :uniqueness => true
validates :email, :presence => true, :uniqueness => true
validates :password, :confirmation => true, :presence => true
validates :password_confirmation, :presence => true
has_many :topics
has_many :comments
before_save :encrypt_password, :if => :password_changed?
def authenticate(password)
self.password_digest==Digest::SHA1::hexdigest(password)
end
def password_changed?
!@password.blank?
end
private
def encrypt_password
self.password_digest=Digest::SHA1::hexdigest(self.password)
end
end
def update_without_password(params, *options)
params.delete(:password)
params.delete(:password_confirmation)
result = update_attributes(params, *options)
clean_up_passwords
result
end
这个代码很简单的,就是 delete,然后调用 update_attributes,可是我自己也是这么做的,还是会 validates,会报错 password 问题。 请问有哪位遇到过的,如何解决呢?
远程把,这年月,soho 应该没有问题的。
我删除了生成的 public/assets 文件夹,结果还是一样的。
我刚才部署到生产环境了,没有这个问题,以为所有的 css 和 js 都合并一个文件了。在测试环境使用 rails s 启动,有时候会有这个问题。有时候又没有这个问题。
jquery.js 重复加载也重复吗,这块的文档,稍后我读一下。
加上了,没有动过页面,一会好用,一会不好用,当然肯定是哪里出了问题,我也正在找。
所有文件都起一个自己用的后缀,然后忽略这个后缀,也是一个办法
不过你要忽略的是所有的文件
能否指定忽略哪个文件呢,应该可以的。
我理解就是一个 where 条件,DRY。
scope 不是用来排序的吧。
没有万能的东西,每一种东西都有它的设计哲学和设计理念,以及设计的初衷。 这个没有什么好比的。 你的产品不可能满足所有用户,每个用户也都有自己的喜好。 用一种东西,就要以他的哲学来思考,来应用,否则你会很痛苦,很纠结,那是你用错了,至少的方式有问题,任何东西都不是橡皮泥,先怎么就怎么。
找一个浏览器可以访问的地址就可以
class Node < ActiveRecord::Base has_many :topics end
class Topic < ActiveRecord::Base belongs_to :node end
@node=Node.find(params[:id]) @topic=@node.topics.build(:title=>"title", :content => "content") #只创建 node 的 topic,不做持久化 @topic.save\
@topic=@node.topics.create(:title => "title", :content => "content")#持久化 topic
必须的
支持
api 不支持,哈哈
你是说在 mongodb 的 console 中 find 出来的数据是保存的,通过界面填写的哪个新字段的值,已经保存好了。但是界面还是提示你失败了。
加入必填字段,已有的记录需要处理一下。 新加的字段,还是必填,肯定有逻辑在里面。 原有的数据需要处理,补上默认值,否则问题多多。
上传多个文件,好像和跨服务器没有什么关系吧。 你说的安全是什么安全呢?你担心出什么安全问题呢? 上传文件的类型,大小,用户权限?
说说你的流程吧,先不要说具体技术,具体如何实现。 创建 create 之后,你想用户看到什么,是看到自己的信息 show,还是看到自己的信息 edit,你自己决定,redirect_to
实在不行,加入自己定义的一个集合,然后把需要的加入,view 绑定自己的集合,不要绑定 model.errors 了。
实时导入,实时处理,这就和需要 100 天数据,然后
100.times{ 访问数据库,一条一条获取 }
是一个问题。
处理耗时任务,需要异步,在另外的线程中处理,告诉用户“正在处理,请稍等”就可以了,然后提供一个界面供他查询处理结果。