qianjigui 发表于 2013-1-23 02:57:28

in_place_editing使用小记

in_place_editing是一个用于原地编辑的ajax小控件。
典型的效果:

http://www.agoit.com/upload/attachment/59162/10b80fb1-72fb-3716-a29c-89eb2c05027f.jpg
 首先请下载相关的rails插件,大家注意:我这里的rails版本是2.1.2,所以原始的插件需要改进。
插件原始地址:http://svn.rubyonrails.org/rails/plugins/in_place_editing/
插件相关改进的讨论:http://railsforum.com/viewtopic.php?id=22457
这是我根据相关的讨论修改后的版本:http://qianjigui.iteye.com/upload/attachment/59164/1ddb2805-c9ce-3a9a-9d03-f950017857f4.zip
 
下面是具体的步骤:
<ol>创建测试应用
rails test添加需要使用的插件cd test/vendor/plugins/ls=> in_place_editing.zipunzip in_place_editing.zip
添加一个数据表ruby script/generate scaffold account#需要根据自己系统的特点配置 config/database.yml#gvim db/migrate/20081212144700_create_accounts.rbclass CreateAccounts < ActiveRecord::Migrationdef self.up    create_table :accounts do |t|      t.column :name, :string      t.column :id_card, :string      t.column :email, :string      t.timestamps    endenddef self.down    drop_table :accountsendend # MySQL.Versions 4.1 and 5.0 are recommended.## Install the MySQL driver:#   gem install mysql# On Mac OS X:#   sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql# On Mac OS X Leopard:#   sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config#       This sets the ARCHFLAGS environment variable to your native architecture# On Windows:#   gem install mysql#       Choose the win32 build.#       Install MySQL and put its /bin directory on your path.## And be sure to use new-style password hashing:#   http://dev.mysql.com/doc/refman/5.0/en/old-client.htmldevelopment:adapter: mysqlencoding: utf8database: test_developmentusername: testmysqlpassword: ******host: localhostsocket: /var/run/mysqld/mysqld.sock# Warning: The database defined as "test" will be erased and# re-generated from your development database when you run "rake".# Do not set this db to the same as development or production.test:adapter: mysqlencoding: utf8database: test_testusername: testmysqlpassword: ******host: localhostproduction:adapter: mysqlencoding: utf8database: test_productionusername: testmysqlpassword: ******host: localhost 运行rakerake db:migrate
下面我们在做了基础设施后,开始我们的具体使用吧:
#插入必要的javascript到layout(app/views/layouts/accounts.html.erb )中<%= javascript_include_tag :defaults %>#得到完整的文件<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><title>Accounts: <%= controller.action_name %></title><%= stylesheet_link_tag 'scaffold' %><%= javascript_include_tag :defaults %></head><body><p style="color: green"><%= flash[:notice] %></p><%= yield%></body></html> 阅读插件的README我们了解到,需要给使用这个插件的Controller添加相应的配置方法<div class="quote_title">README 写道
页: [1]
查看完整版本: in_place_editing使用小记