Ruby on rails 调用数据库函数以更新用户详细信息
在使用下面的代码更新用户密码时,是否有方法使用此PostgreSQL函数Ruby on rails 调用数据库函数以更新用户详细信息,ruby-on-rails,ruby,postgresql,Ruby On Rails,Ruby,Postgresql,在使用下面的代码更新用户密码时,是否有方法使用此PostgreSQL函数crypt(“”,gen_salt('bf')) def update @player = Player.find(params[:id]) respond_to do |format| if @player.update_attributes(params[:player]) flash[:notice] = 'Player was successfully updated.' f
crypt(“”,gen_salt('bf'))
def update
@player = Player.find(params[:id])
respond_to do |format|
if @player.update_attributes(params[:player])
flash[:notice] = 'Player was successfully updated.'
format.html { redirect_to(@player) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @player.errors, :status => :unprocessable_entity }
end
end
end
至少有一种方法可以在update-update\u all方法中使用纯SQL 因此,要使用Postgres crypt方法更新玩家的密码,您可以执行以下操作:
Player.update_all "password = crypt('<password>', gen_salt('bf'))", "id = #{params[:id]}"
Player.update_all“password=crypt(“”,gen_salt('bf')),“id={params[:id]}”
为什么要将与应用程序相关的问题推到数据存储中?即使每次调用的性能更高,但当您尝试扩展时,您的数据库通常是您的瓶颈。@coreyward:true,但问题仍然很有趣。:-)