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

首先请下载相关的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::Migration def self.up create_table :accounts do |t| t.column :name, :string t.column :id_card, :string t.column :email, :string t.timestamps end end def self.down drop_table :accounts endend # 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: mysql encoding: utf8 database: test_development username: testmysql password: ****** host: localhost socket: /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: mysql encoding: utf8 database: test_test username: testmysql password: ****** host: localhostproduction: adapter: mysql encoding: utf8 database: test_production username: testmysql password: ****** 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 写道 |
|