浏览 3443 次
锁定老帖子 主题:Flex on Rails 实例(一)
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-10-27
以下的例子我们在ubuntu下,(例子引用Manning.Flexible.Rails)
netbeans6.1 +rails2.1+Flex3 SDK+ruby1.86环境下执行 创建一个项目命名为:pomodo ~/NetBeansProjects$ rails pomodo ~/NetBeansProjects$ cd pomodo ~/NetBeansProjects/pomodo$ rake rails:freeze:gems 项目创建好了,rails版本也lock了 下面使用一个restful_authentication插件 ~/NetBeansProjects/pomodo$ ./script/plugin install -r 3072 http://svn.techno-weenie.net/projects/plugins/restful_authentication/ + ./README + ./Rakefile + ./generators/authenticated/USAGE ...output omitted... 确定已经显示以上信息,这个插件是创建用户登录功能的 下面我们通过插件生成了user和sessions ~/NetBeansProjects/pomodo$./script/generate authenticated user sessions 修改user的迁移文件 db\migrate\20081007123744_create_users.rb class CreateUsers < ActiveRecord::Migration def self.up create_table "users", :force => true do |t| t.column :login, :string t.column :email, :string t.column :first_name, :string, :limit => 80 t.column :last_name, :string, :limit => 80 t.column :crypted_password, :string, :limit => 40 t.column :salt, :string, :limit => 40 t.column :created_at, :datetime t.column :updated_at, :datetime t.column :remember_token, :string t.column :remember_token_expires_at, :datetime end end def self.down drop_table "users" end end 修改数据库配置文件 database.yml development: adapter: mysql encoding: utf8 database: pomodo_development username: root(输入自己正确的mysql用户名) password: root(输入自己正确的mysql密码) socket: /var/run/mysqld/mysqld.sock 迁移文件 ~/NetBeansProjects/pomodo$rake db:create:all (创建数据库) ~/NetBeansProjects/pomodo$rake db:migrate(执行迁移) ~/NetBeansProjects/pomodo$ mysql -uroot -p mysql> show databases; Database | +-----------------------+ | information_schema | | mysql | | omdb_dev | | pomodo_development | | pomodo_production | | pomodo_test mysql> use pomodo_development; mysql> select * from users; 修改模型user,增加如下内容 app\models\user.rb ... # prevents a user from submitting a crafted form that bypasses # activation # anything else you want your user to change should be added # here. attr_accessible :login, :email, :password, :password_confirmation, :first_name, :last_name ... 增加 RESTful routes config\routes.rb ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: # first created -> highest priority. ... # Sample resource route (maps HTTP verbs to controller actions # automatically): # map.resources :products map.resources :users map.resource :session signup URL map.signup '/signup', :controller => 'users', :action => login URL map.login '/login', :controller => 'sessions', :action => 'new' logout URL map.logout '/logout', :controller => 'sessions', :action => 'destroy' # Sample resource route with options: # map.resources :products, # :member => { :short => :get, :toggle => :post }, # :collection => { :sold => :get } ... end Modifying the includes and before_filter as instructed by the comments app\controllers\sessions_controller.rb app\controllers\users_controller.rb 分别在上面两个控制器中,删除include AuthenticatedSystem 把include AuthenticatedSystem加到app\controllers\application.rb 并将protect_from_forgery 注释 app\controllers\application.rb # Filters added to this controller apply to all controllers in # the application. Likewise, all the methods added will be # available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time include AuthenticatedSystem # See ActionController::RequestForgeryProtection for details # Uncomment the :secret if you're not using the cookie session # store # TODO - this will be uncommented once we explain sessions # in iteration 5. # protect_from_forgery # :secret => 'dd92c128b5358a710545b5e755694d57' end 完成修改后启动web服务器,我们这里用默认的webrick ~/NetBeansProjects/pomodo$ ./script/server webrick 使用http://localhost:3000/signup 访问注册用户 http://localhost:3000/login 登录 ,下篇将是详细介绍flex编译 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-10-27
你这还没有写完吧,这个只能说是“用estful Authentication插件来用户登录"的例子,期待你的完善。
|
|
返回顶楼 | |
发表时间:2008-10-27
qichunren 写道 你这还没有写完吧,这个只能说是“用estful Authentication插件来用户登录"的例子,期待你的完善。
这还没涉及到flex编译呢,下篇就是flex编译详解了 |
|
返回顶楼 | |
发表时间:2008-10-27
做 Flex 和 Rails 开发都有一段时间了,但是我现在还没来得及看那本 Flexible Rails, 真该翻翻了。
|
|
返回顶楼 | |