1. 自动的数据库加载工具
应该用好rake工具,它就像make工具给开发人员提供了一键式服务模式.以添加数据库表为例:
rake db:migrate
会自动执行db/migrate/*.rb所有文件.
当然migrate文件也许要按照一定格式书写.
2. 通过javascript达到url链接的post提交方式.
关于为什么需要使用post提交方式,在滑板书上有详细介绍.在这里不再赘述.
在书写的时候非常简单
<%= link_to 'Destroy', { :action => 'destroy', :id => product },:confirm =>'Are you sure?',:post => true %>
不知道我这里是否是2.1版本的原因,这种配置无法达到post的效果,需要换一种书写方式.
<%= link_to 'Destroy', { :action => 'destroy', :id => product },:confirm => 'Are you sure?',:method => :post %>
这是2.1 rdoc中的讲解:
:method => symbol of HTTP verb - This modifier will dynamically create an HTML form and immediately submit the form for processing using the HTTP verb specified. Useful for having links perform a POST operation in dangerous actions like deleting a record (which search bots can follow while spidering your site). Supported verbs are :post, :delete and :put. Note that if the user has JavaScript disabled, the request will fall back to using GET. If you are relying on the POST behavior, you should check for it in your controller‘s action by using the request object‘s methods for post?, delete? or put?.
3. 将session放在数据库中
rake db:sessions:create
class CreateSessions < ActiveRecord::Migration
def self.up
create_table :sessions do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
add_index :sessions, :session_id
add_index :sessions, :updated_at
end
def self.down
drop_table :sessions
end
end
将environment.rb文件中的config.action_controller.session_store = :active_record_store注释去掉即可
4. rjs模板文件的学习
ROR version 1.1.2 学习笔记(本地环境已经达到了2.1)
最新推荐文章于 2024-06-11 14:01:40 发布