- 浏览: 74925 次
- 性别:
- 来自: 地球
最近访客 更多访客>>
文章分类
最新评论
-
zhou1986lin:
[flash=200,200][b]引用[size=x-sma ...
新浪编辑器 -
vb2005xu:
晕 想不出来 为什么要实现 什么什么语言的 版本的好处
不都是 ...
新浪编辑器 -
minma_yuyang:
还不错,借鉴了。
Code style -
天机老人:
谢谢啊,这文章不错!
Sphinx -
suncanoe:
<iframe id="myEditor&qu ...
新浪编辑器
从文本字段读取数据
输入视图:
<form action = "\look\at">
...
<input type="text" name="text1">
...
</form>
动作:
def at
@date = params[:text1]
end
输出视图:
<br>
Your Name is <% = @date %>
</br>
从复选框读取数据
输入视图:
<form action = "\look\at">
..
<input type="checkbox" name="check1">
..
</form>
动作:
def at
@date = params[:check1]
end
输出视图:
<br>
<% if @data %>
You clicked yes.
<% else %>
You did not click yes.
<% end %>
<br>
从单选按钮中读取数据
输入视图:
<form action="\look\at">
...
<input type="radio" name="radio1" value="red">red
<input type="radio" name="radio1" value="blue">blue
<input type="radio" name="radio1" value="green">green
...
</fomr>
动作:
def at
@data = params[:radios1]
end
输出视图:
<br>
You selected <%= @data %>.
<br>
从选择框读取数据
输入视图:
<form action = "\look\at">
Select your new car's color.
<br>
<select name="select1" >
<option value="red">red
<option value="green">green
<option value="blue">blue
</select>
<br>
<br>
<input type="submit"/>
</form>
动作:
def at
@data = params[:select1]
end
输出视图:
<br>
Your Select <% = @date %>
</br>
从选择框读取多个选择
输入视图:
<form action = "\look\at">
Select your new car's color.
<br>
<select name="select1[]" multiple size="3">
<option value="red">red
<option value="green">green
<option value="blue">blue
</select>
<br>
<br>
<input type="submit"/>
</form>
动作相同
输出视图:
<br>
You selected <% for data in @data %>
<%= data %>
<% end %>
<br>
Rails中使用HTML的快捷方法
输入视图:
<%= start_form_tag ({:action => "at"}, {:method => "post"}) %>
Please enter your name.
<br>
<%= text_field_tag ("text1", "", {"size" => 30}) %>
<br>
<br>
<input type="submit"/>
<%= end_form_tag %>
动作:
def at
@data = params[:text1]
end
def input
end
新增加了一个input方法,所以上面的视图是保存在以.rhtml结尾的文件中
输出视图:
<br>
Your name is <%= @data %>.
<br>
给start_form_tag 方法传递了一个指定动作的散列表,以及一个可选的散列表选项--有两个选项:"method"可以是"get"或"post", ":multipart"可以是"true"或"false"
使用text_field_tag 方法创建文本字段,需要将文本字段的名称,在文本字段中显示的初始文本以及一个可选的用于设置标准HTML选项--:disable,:maxsize或:size--的散列表传递给这个方法
创建复选框用check_box_tag方法,创建单选按钮使用radio_button_tag方法。
创建check_box:
<%= start_form_tag ({:action => "at"}, {:method => "post"}) %>
Would you like a raise?
<br>
<br>
<%= check_box_tag ("check1", "Yes", false) %>Yes
<br>
<br>
<input type="submit"/>
<%= end_form_tag %>
创建select:
<%= start_form_tag ({:action => "at"}, {:method => "post"}) %>
Select your new car's color.
<br>
<br>
<%= select_tag ("select1[]", "<option value='red'>red<option value='green'>green<option
value='blue'>blue", {:multiple => true}) %>
<br>
<br>
<input type="submit"/>
<%= end_form_tag %>
使用模型:
只需要在应用程序的module目录下放置一个.rb文件就能创建模型。
使用模型:在动作中创建一个模型的对象,使用这个对象的方法。
模型的代码:
class Cruncher
def crunch
return 5
end
end
使用模型:
def at
@cruncher = Cruncher.new
@data = @cruncher.crunch
end
绑定控件和模型
rails支持一系列方法--text_field,select,check_box,可以使用这些方法直接将HTML控件连接到模型。
text_field(object_name, method, {...})
object_name是模型对象的名字,method是需要与之绑定的控件的数据访问器名称,{...}是一个包含有这个文本字段的HTML设置的散列表,如{"size" => 30}
模型:
class Cruncher
attr_reader :crunch
attr_writer :crunch
def initialize(data)
@crunch = data
end
end
动作:
def at
@data_hash = params[:cruncher]
@cruncher = Cruncher.new(@data_hash[:crunch])
@data = @cruncher.crunch
end
def input
end
输入视图:
<%= start_form_tag ({:action => "at"}, {:method => "post"}) %>
Please enter your name.
<br>
<%= text_field ("cruncher", "crunch", {"size" => 30}) %>
<br>
<br>
<input type="submit"/>
<%= end_form_tag %>
输出视图:
<br>
Your name is <%= @data %>.
<br>
在视图中使用cruncher对象将文本字符中的数据绑定到这个crunch属性。
文本字符中的数据会在以:cruncher为参数的散列表中传回。
初始化控件中的数据
只需要在动作中,修改input动作:
def input
@cuncher = Cruncher.crunch
end
存储会话中的数据
session[:data] = @data
输入视图:
<form action = "\look\at">
...
<input type="text" name="text1">
...
</form>
动作:
def at
@date = params[:text1]
end
输出视图:
<br>
Your Name is <% = @date %>
</br>
从复选框读取数据
输入视图:
<form action = "\look\at">
..
<input type="checkbox" name="check1">
..
</form>
动作:
def at
@date = params[:check1]
end
输出视图:
<br>
<% if @data %>
You clicked yes.
<% else %>
You did not click yes.
<% end %>
<br>
从单选按钮中读取数据
输入视图:
<form action="\look\at">
...
<input type="radio" name="radio1" value="red">red
<input type="radio" name="radio1" value="blue">blue
<input type="radio" name="radio1" value="green">green
...
</fomr>
动作:
def at
@data = params[:radios1]
end
输出视图:
<br>
You selected <%= @data %>.
<br>
从选择框读取数据
输入视图:
<form action = "\look\at">
Select your new car's color.
<br>
<select name="select1" >
<option value="red">red
<option value="green">green
<option value="blue">blue
</select>
<br>
<br>
<input type="submit"/>
</form>
动作:
def at
@data = params[:select1]
end
输出视图:
<br>
Your Select <% = @date %>
</br>
从选择框读取多个选择
输入视图:
<form action = "\look\at">
Select your new car's color.
<br>
<select name="select1[]" multiple size="3">
<option value="red">red
<option value="green">green
<option value="blue">blue
</select>
<br>
<br>
<input type="submit"/>
</form>
动作相同
输出视图:
<br>
You selected <% for data in @data %>
<%= data %>
<% end %>
<br>
Rails中使用HTML的快捷方法
输入视图:
<%= start_form_tag ({:action => "at"}, {:method => "post"}) %>
Please enter your name.
<br>
<%= text_field_tag ("text1", "", {"size" => 30}) %>
<br>
<br>
<input type="submit"/>
<%= end_form_tag %>
动作:
def at
@data = params[:text1]
end
def input
end
新增加了一个input方法,所以上面的视图是保存在以.rhtml结尾的文件中
输出视图:
<br>
Your name is <%= @data %>.
<br>
给start_form_tag 方法传递了一个指定动作的散列表,以及一个可选的散列表选项--有两个选项:"method"可以是"get"或"post", ":multipart"可以是"true"或"false"
使用text_field_tag 方法创建文本字段,需要将文本字段的名称,在文本字段中显示的初始文本以及一个可选的用于设置标准HTML选项--:disable,:maxsize或:size--的散列表传递给这个方法
创建复选框用check_box_tag方法,创建单选按钮使用radio_button_tag方法。
创建check_box:
<%= start_form_tag ({:action => "at"}, {:method => "post"}) %>
Would you like a raise?
<br>
<br>
<%= check_box_tag ("check1", "Yes", false) %>Yes
<br>
<br>
<input type="submit"/>
<%= end_form_tag %>
创建select:
<%= start_form_tag ({:action => "at"}, {:method => "post"}) %>
Select your new car's color.
<br>
<br>
<%= select_tag ("select1[]", "<option value='red'>red<option value='green'>green<option
value='blue'>blue", {:multiple => true}) %>
<br>
<br>
<input type="submit"/>
<%= end_form_tag %>
使用模型:
只需要在应用程序的module目录下放置一个.rb文件就能创建模型。
使用模型:在动作中创建一个模型的对象,使用这个对象的方法。
模型的代码:
class Cruncher
def crunch
return 5
end
end
使用模型:
def at
@cruncher = Cruncher.new
@data = @cruncher.crunch
end
绑定控件和模型
rails支持一系列方法--text_field,select,check_box,可以使用这些方法直接将HTML控件连接到模型。
text_field(object_name, method, {...})
object_name是模型对象的名字,method是需要与之绑定的控件的数据访问器名称,{...}是一个包含有这个文本字段的HTML设置的散列表,如{"size" => 30}
模型:
class Cruncher
attr_reader :crunch
attr_writer :crunch
def initialize(data)
@crunch = data
end
end
动作:
def at
@data_hash = params[:cruncher]
@cruncher = Cruncher.new(@data_hash[:crunch])
@data = @cruncher.crunch
end
def input
end
输入视图:
<%= start_form_tag ({:action => "at"}, {:method => "post"}) %>
Please enter your name.
<br>
<%= text_field ("cruncher", "crunch", {"size" => 30}) %>
<br>
<br>
<input type="submit"/>
<%= end_form_tag %>
输出视图:
<br>
Your name is <%= @data %>.
<br>
在视图中使用cruncher对象将文本字符中的数据绑定到这个crunch属性。
文本字符中的数据会在以:cruncher为参数的散列表中传回。
初始化控件中的数据
只需要在动作中,修改input动作:
def input
@cuncher = Cruncher.crunch
end
存储会话中的数据
session[:data] = @data
发表评论
-
架起自己的blog, 以后我的博客将更新至 http://kunlunblogs.herokuapp.com
2010-03-09 12:11 814博客辗转几个地方, 最终还是去heroku吧 http://k ... -
检查并显示mobile页面
2010-03-05 13:39 758根据user_agent判断是否是手机设备 reque ... -
给任务传递参数
2010-03-05 10:45 867desc 'For test params' task ... -
扩展paperclip 增加watermark
2010-03-05 01:46 12391. /lib/paperclip processors ad ... -
rails read digital photo
2010-03-05 01:28 8561 gem install exifr 2 $ irb -r ... -
rails' cron rufus-scheduler
2010-03-04 15:49 12351 installation sudo gem inst ... -
searchlogic
2010-03-03 14:57 783This plugin help searching. you ... -
capistrano配置
2010-03-02 16:21 1414服务器文件结构 mya ... -
passenger 工具查看内存状态
2010-03-02 15:59 9981. inspect Phusion Passenger’s ... -
passenger apache 设定
2010-03-02 15:56 947sudo vim /etc/apache2/httpd.con ... -
rails plugin-- auto_migrations
2010-03-02 12:09 785一般我们更改表结构的时候,数据会自动清空,挺麻烦的。auto_ ... -
a question
2010-01-28 20:10 804目前,经理想知道从A地址(例如10.1.3.1)到B地址(例如 ... -
在日志中过滤password
2010-01-28 14:00 803在user controller中加入 filter_para ... -
radiantcms
2009-12-02 17:33 714http://radiantcms.org/overview/ ... -
file copy
2009-06-23 14:39 839require 'ftools' namespace :ae ... -
copy files from original dir to other dir
2009-06-23 14:35 711namespace :ae do desc &quo ... -
ActionMailer 发送 email
2009-05-19 18:57 883配置 environment -- development.r ... -
Ruby rake file
2009-05-14 15:20 841task :import_projects => :en ... -
Mini_magick
2009-05-14 13:18 1286MiniMagick中Image对象有一个shave方法,正好 ... -
匹配所有路由
2009-05-14 11:57 600*path hehe
相关推荐
Rails View Best Practices
You’ll learn how to create something visible with Rails’ view layer before diving into the more difficult inner layers: the database models and controller code. All you need to begin your Rails ...
分别介绍了Rails的环境、初始过程、配置和日志记录,Rails的分配器、控制器、页面生成和路由,REST、资源和Rails,ActiveRecord的基础、关联、验证和高级技巧,ActionView的模板、缓存和帮助器,Ajax、Prototype和...
简介 Ruby On Rails 框架自它提出之日...Rails 是一个真正彻底的 MVC(Model-View-Controller) 框架,Rails 清楚地将你的模型的代码与你的控制器的应用逻辑从 View 代码中分离出来。Rails 开发人员很少或者可能从未遇到
rails, Ruby on Rails 欢迎使用 RailsRails 是一个web应用程序框架,它包括根据 Model-View-Controller ( MVC ) Pattern 创建数据库备份的web应用程序所需的所有内容。理解 MVC Pattern 是理解 Rai
With this fully revised new edition, take a holistic view of full-stack development to create usable, high-performing applications with Rails 5. Rails is a great tool for building web applications, ...
You'll find no substitute for the guru's-eye-view of design, testing, deployment, and other real-world concerns that this book provides. Rails 4 in Action is a hands-on guide to the subject. In this...
Rails::API 移除了 ActionView 和其他一些渲染功能,不关心Web前端的开发者可更容易、快速地开发应用程序,因此运行速度比正常的 Rails 应用程序要快。 Rails::API 可以用来创建只提供API服务(API-Only)的 Rails ...
Use Rails scaffolding to build applications from a view-centric perspective • Add common web application elements such as sessions, cookies, and authentication • Build applications that combine ...
upmin-admin 是一个为 Rails 应用开发的开源管理框架。用来管理 Rails 应用中各种对象(如 Model、View 和 Controller )。 标签:upmin
You’ll learn how to create something visible with Rails’ view layer before diving into the more difficult inner layers: the database models and controller code. All you need to begin your Rails ...
You’ll learn how to create something visible with Rails’ view layer before diving into the more difficult inner layers: the database models and controller code. All you need to begin your Rails ...
View * Move code into controller * Move code into helper * Replace instance variable with local variable Ruby5 不久前在2009年11月17日的Podcast中介绍了rails_best_practices,而railscasts.com的Ryan...
Ruby on Rails的性能调优方案研究,张淼森,杨杰,Ruby on Rails 框架自它提出之日起就受到广泛关注。由于Rails框架基于MVC(Model-View-Controller) 模型,可以清楚地将模型层的代码与控制层的应
准的编程模式,比如ActiveRecord 以及Model-View-Controller。它重用很多已经存在 的Ruby 库(比如Rake和ERb)。Rails 的功能在于集成这些标准的技术自动化完成任务, 并且会断言合理的默认行为。
Rails的设置 Ruby gem通过将...class User < ActiveRecord xss=removed> { :theme => 'blue' , :view => 'monthly' , :filter => false } s . key :calendar , :defaults => { :scope => 'company' } end end
rails-dom-testing, 从ActionView中提取DomAssertions和 SelectorAssertions 命令行:::: dom:: 测试这里 gem 负责比较 HTML in,并断言在 Rails 应用程序中存在DOM元素。 通过 assert_dom_equal 和 assert_dom_not_...
* Base an ActiveRecord model on a database view, and build support for multiple table inheritance * Explore service-oriented architecture and web services with XML-RPC and REST * See how caching ...