道喜技术日记 .^. 天天红玉世界

Rails Ruby MacOSX 。。。创新来自于刻苦的实践和勤奋的思考... www.hhtong.com


Rails实例世界(No 4):REST_in_Place on Rails编辑器

Gudao Luo2009-02-11 at 21:34发表的

REST_in_Place on Rails编辑器
使用REST_in_Place命令和代码清单
rails demo_rest-in-place && cd demo_rest-in-place
ruby script/plugin install git://github.com/janv/rest_in_place.git
wget -O public/javascripts/jquery-1.2.6.min.js http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js
ruby script/generate scaffold user name:string
vim app/views/layouts/users.html.erb
# 在users.html.erb增加下面所有代码
<title>Users: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
<%= javascript_include_tag "jquery-1.2.6.min" , "jquery.rest_in_place" %>
<script type="text/javascript">
rails_authenticity_token = '<%= form_authenticity_token %>'
</script>
vim app/controllers/users_controller.rb
# 在users_controller.rb增加一行代码
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @user }
format.js { render :json => @user }
end
end
vim app/views/users/show.html.erb
# 在show.html.erb增加下面所有代码
<div id="<%= dom_id @user %>">
ID: <%= @user.id %><br />
Name: <span class="rest_in_place" attribute="name"><%= @user.name %></span>
</div>
rake db:drop && rake db:migrate && rake db:fixtures:load
ruby script/server
open http://localhost:3000/users/<show_id>
Hierarchy: previous, next