RUBYʵ¼ù—´øÃÜÂë¼ÓÃܵÄÓû§´´½¨¼°ÐÞ¸Ä
¿ª·¢»·¾³
Ruby: Ruby1.9.1
Rails: Rails2.3.5
Mysql:Mysql5.0.9
Driver:mysql-2.8.1-x86-mingw32.gem
IDE:Rubymine2.0.1
Ò»¡¢´´½¨Êý¾Ý±íUsers
ÀûÓÃRubyMine×Ô´øµÄScaffold¹¤¾ß´´½¨Êý¾Ý±íUsers£¬Ò²¿ÉÒÔÊÖ¶¯´´½¨
¶þ¡¢´´½¨ControllerºÍView
RubyÏîÄ¿—>ÓÒ¼ü—>Create Model
Íê³Éºó½«×Ô¶¯Éú³ÉÏàÓ¦µÄÎļþ
Èý¡¢ÐÞ¸ÄModel user.rb
ÀûÓÃDigest/SHA1¶ÔÃÜÂë½øÐмÓÃÜ£¬ÊµÏÖ¼ÓÃܱ£´æ
Ð޸ĺó´úÂëÈçÏ£º
require "digest/sha1"
class User < ActiveRecord::Base
attr_accessor :hashed_password,:repassword
attr_accessible :username, :hashed_password, :repassword
validates_uniqueness_of :username
validates_presence_of :username, :hashed_password
def before_create
self.password = User.hash_password(self.hashed_password)
end
def after_create
@hashed_password = nil
end
def before_update
self.password = User.hash_password(self.hashed_password)
end
def after_update
@hashed_password = nil
end
private
def self.hash_password(hashed_password)
Digest::SHA1.hexdigest(hashed_password)
end
end
ËÄ¡¢ÐÞ¸Äusers_controller.rb
ÐÞ¸Äupdate·½·¨£¬ÊµÏÖµ±½øÐÐedit²Ù×÷ʱÏÈÅжÏpasswordÓë password_confirmÊÇ·ñÒ»Ö£¬
Èç¹ûÒ»Ö£¬Ôò½øÐÐupdate²Ù×÷£¬·ñÔòÌáʾÓû§password Óë password_confirm ÊäÈë²»Ò»ÖÂ
Ð޸ĺó´úÂëÈçÏ£º
def update
@user = User.find(params[:id])
respond_to do |format|
print "user: #{params[:user]}"
if params[:user]["hashed_password"] == params[:user]["repassword"]
if @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
format.html { redirect_to(@user) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
else
flash[:notice] = 'Password and Password confirm are not the same'
format.html { render :action => "edit" }
format.xml
Ïà¹ØÎĵµ£º
ת×Ô http://www.javaeye.com/topic/57474
Windowsƽ̨µÄruby IDE µãÆÀ
ÔÚMacOSƽ̨¼¸ºõûÓÐʲôÕùÒéÐÔ£¬´ó¼Ò¶¼ÓÃTextMate¡£µ«ÊÇWindowsƽ̨¿É¹©Ñ¡ÔñºÍʹÓõÄIDEºÜ¶à£¬È´¸÷Óи÷µÄ³¤´¦ºÍ¶Ì´¦¡£»ùÓÚÎÒÓùýµÄËùÓÐruby IDEµãÆÀһϡ£windowsƽ̨µÄRoR IDEÖ÷Òª·ÖΪÁ½ÀࣺһÀàÊÇÖØÁ¿¼¶µÄÈ«¹¦ÄÜIDE£¬ÀýÈçEclipse£¬Netbeans ......
¿ª·¢»·¾³£º
OS:Windows XP
Ruby:Ruby1.9.1
Rails:Rails2.3.5
will_paginate:will_paginate2.3.11
(ÔÚÃüÁîÐÐÖÐÔËÐÐ gem install mislav-will_paginate --source http://gems.github.com )
IDE:Rubymine2.0.1
DB:mysql5.0.9
±¾ÀýÔÚÉÏÒ»¸öÀý×Ó£¨Rubyʵ¼ù—¼òµ¥Êý¾Ý¿â²Ù×÷£©µÄ»ù´¡ÉÏʵÏÖ·ÖÒ³£¬ÀûÓõÄÊÇwill_p ......
RESTfulµÄ»¯Éí----resource
µ±È»£¬¹â°ÑRESTfulºÍresource³¶µ½Ò»ÆðËÆºõÏ൱ÏÁÒ壬ÔÚRailsÖУ¬ActionController::Resources³éÏóÁËRESTÖеÄResource£¬ÕâÀÎÒ²»Ì¸RESTµÄÏà¹Ø¸ÅÄî£¬ÍøÉÏ×ÊÁÏÒ»´óÛç¡£ÎÒÃǾÍÀ´¿´¿´RailsÖÐÊÇÈçºÎͨ¹ýResourceÀ´ÇáËÉ£¬¼ò±ãµÄÍê³ÉRESTfulÓ¦Óõİɡ£
resources.rb
Ô´´úÂë ......
Ruby ÀàµÄ¼Ì³Ð
¹Ø¼ü×Ö: Ruby ÀàµÄ¼Ì³Ð
Ò»¡¢ÆÕͨ·½Ê½µÄ¼Ì³Ð
RubyÖ»Ö§³Öµ¥¼Ì³Ð
ruby ´úÂë
class
Child < Father
......
end
ObjectÊÇËùÓÐÀàµÄÊ¼×æ£¬²¢ÇÒObjectµÄʵÀý·½·¨ ......