- 浏览: 2076081 次
- 性别:
- 来自: NYC
文章分类
- 全部博客 (628)
- Linux (53)
- RubyOnRails (294)
- HTML (8)
- 手册指南 (5)
- Mysql (14)
- PHP (3)
- Rails 汇总 (13)
- 读书 (22)
- plugin 插件介绍与应用 (12)
- Flex (2)
- Ruby技巧 (7)
- Gem包介绍 (1)
- javascript Jquery ext prototype (21)
- IT生活 (6)
- 小工具 (4)
- PHP 部署 drupal (1)
- javascript Jquery sort plugin 插件 (2)
- iphone siri ios (1)
- Ruby On Rails (106)
- 编程概念 (1)
- Unit Test (4)
- Ruby 1.9 (24)
- rake (1)
- Postgresql (6)
- ruby (5)
- respond_to? (1)
- method_missing (1)
- git (8)
- Rspec (1)
- ios (1)
- jquery (1)
- Sinatra (1)
最新评论
-
dadadada2x:
user模型里加上 protected def email ...
流行的权限管理 gem devise的定制 -
Sev7en_jun:
shrekting 写道var pattern = /^(0| ...
强悍的ip格式 正则表达式验证 -
jiasanshou:
好文章!!!
RPM包rpmbuild SPEC文件深度说明 -
寻得乐中乐:
link_to其实就是个a标签,使用css控制,添加一个参数: ...
Rails在link_to中加参数 -
aiafei0001:
完全看不懂,不知所然.能表达清楚一点?
"$ is not defined" 的问题怎么办
render是一个个人比较喜欢工具,先列一些常用的吧
放到这里,用的时候好找,呵呵
render :action => "long_goal", :layout => "spectacular" render :partial => "person", :locals => { :name => "david" } render :template => "weblog/show", :locals => {:customer => Customer.new} render :file => "c:/path/to/some/template.erb", :layout => true, :status => 404 render :text => "Hi there!", :layout => "special" render :text => proc { |response, output| output.write("Hello from code!") } render :xml => {:name => "David"}.to_xml render :json => {:name => "David"}.to_json, :callback => 'show' render :inline => "<%= 'hello ' + name %>", :locals => { :name => "david" } render :js => "alert('hello')" render :xml => post.to_xml, :status => :created, :location => post_url(post)
放到这里,用的时候好找,呵呵
Renders the content that will be returned to the browser as the response body. Rendering an action Action rendering is the most common form and the type used automatically by Action Controller when nothing else is specified. By default, actions are rendered within the current layout (if one exists). # Renders the template for the action "goal" within the current controller render :action => "goal" # Renders the template for the action "short_goal" within the current controller, # but without the current active layout render :action => "short_goal", :layout => false # Renders the template for the action "long_goal" within the current controller, # but with a custom layout render :action => "long_goal", :layout => "spectacular" Rendering partials Partial rendering in a controller is most commonly used together with Ajax calls that only update one or a few elements on a page without reloading. Rendering of partials from the controller makes it possible to use the same partial template in both the full-page rendering (by calling it from within the template) and when sub-page updates happen (from the controller action responding to Ajax calls). By default, the current layout is not used. # Renders the same partial with a local variable. render :partial => "person", :locals => { :name => "david" } # Renders the partial, making @new_person available through # the local variable 'person' render :partial => "person", :object => @new_person # Renders a collection of the same partial by making each element # of @winners available through the local variable "person" as it # builds the complete response. render :partial => "person", :collection => @winners # Renders a collection of partials but with a custom local variable name render :partial => "admin_person", :collection => @winners, :as => :person # Renders the same collection of partials, but also renders the # person_divider partial between each person partial. render :partial => "person", :collection => @winners, :spacer_template => "person_divider" # Renders a collection of partials located in a view subfolder # outside of our current controller. In this example we will be # rendering app/views/shared/_note.r(html|xml) Inside the partial # each element of @new_notes is available as the local var "note". render :partial => "shared/note", :collection => @new_notes # Renders the partial with a status code of 500 (internal error). render :partial => "broken", :status => 500 Note that the partial filename must also be a valid Ruby variable name, so e.g. 2005 and register-user are invalid. Automatic etagging Rendering will automatically insert the etag header on 200 OK responses. The etag is calculated using MD5 of the response body. If a request comes in that has a matching etag, the response will be changed to a 304 Not Modified and the response body will be set to an empty string. No etag header will be inserted if it‘s already set. Rendering a template Template rendering works just like action rendering except that it takes a path relative to the template root. The current layout is automatically applied. # Renders the template located in [TEMPLATE_ROOT]/weblog/show.r(html|xml) (in Rails, app/views/weblog/show.erb) render :template => "weblog/show" # Renders the template with a local variable render :template => "weblog/show", :locals => {:customer => Customer.new} Rendering a file File rendering works just like action rendering except that it takes a filesystem path. By default, the path is assumed to be absolute, and the current layout is not applied. # Renders the template located at the absolute filesystem path render :file => "/path/to/some/template.erb" render :file => "c:/path/to/some/template.erb" # Renders a template within the current layout, and with a 404 status code render :file => "/path/to/some/template.erb", :layout => true, :status => 404 render :file => "c:/path/to/some/template.erb", :layout => true, :status => 404 Rendering text Rendering of text is usually used for tests or for rendering prepared content, such as a cache. By default, text rendering is not done within the active layout. # Renders the clear text "hello world" with status code 200 render :text => "hello world!" # Renders the clear text "Explosion!" with status code 500 render :text => "Explosion!", :status => 500 # Renders the clear text "Hi there!" within the current active layout (if one exists) render :text => "Hi there!", :layout => true # Renders the clear text "Hi there!" within the layout # placed in "app/views/layouts/special.r(html|xml)" render :text => "Hi there!", :layout => "special" Streaming data and/or controlling the page generation The :text option can also accept a Proc object, which can be used to: 1. stream on-the-fly generated data to the browser. Note that you should use the methods provided by ActionController::Steaming instead if you want to stream a buffer or a file. 2. manually control the page generation. This should generally be avoided, as it violates the separation between code and content, and because almost everything that can be done with this method can also be done more cleanly using one of the other rendering methods, most notably templates. Two arguments are passed to the proc, a response object and an output object. The response object is equivalent to the return value of the ActionController::Base#response method, and can be used to control various things in the HTTP response, such as setting the Content-Type header. The output object is an writable IO-like object, so one can call write and flush on it. The following example demonstrates how one can stream a large amount of on-the-fly generated data to the browser: # Streams about 180 MB of generated data to the browser. render :text => proc { |response, output| 10_000_000.times do |i| output.write("This is line #{i}\n") output.flush end } Another example: # Renders "Hello from code!" render :text => proc { |response, output| output.write("Hello from code!") } Rendering XML Rendering XML sets the content type to application/xml. # Renders '<name>David</name>' render :xml => {:name => "David"}.to_xml It‘s not necessary to call to_xml on the object you want to render, since render will automatically do that for you: # Also renders '<name>David</name>' render :xml => {:name => "David"} Rendering JSON Rendering JSON sets the content type to application/json and optionally wraps the JSON in a callback. It is expected that the response will be parsed (or eval‘d) for use as a data structure. # Renders '{"name": "David"}' render :json => {:name => "David"}.to_json It‘s not necessary to call to_json on the object you want to render, since render will automatically do that for you: # Also renders '{"name": "David"}' render :json => {:name => "David"} Sometimes the result isn‘t handled directly by a script (such as when the request comes from a SCRIPT tag), so the :callback option is provided for these cases. # Renders 'show({"name": "David"})' render :json => {:name => "David"}.to_json, :callback => 'show' Rendering an inline template Rendering of an inline template works as a cross between text and action rendering where the source for the template is supplied inline, like text, but its interpreted with ERb or Builder, like action. By default, ERb is used for rendering and the current layout is not used. # Renders "hello, hello, hello, again" render :inline => "<%= 'hello, ' * 3 + 'again' %>" # Renders "<p>Good seeing you!</p>" using Builder render :inline => "xml.p { 'Good seeing you!' }", :type => :builder # Renders "hello david" render :inline => "<%= 'hello ' + name %>", :locals => { :name => "david" } Rendering inline JavaScriptGenerator page updates In addition to rendering JavaScriptGenerator page updates with Ajax in RJS templates (see ActionView::Base for details), you can also pass the :update parameter to render, along with a block, to render page updates inline. render :update do |page| page.replace_html 'user_list', :partial => 'user', :collection => @users page.visual_effect :highlight, 'user_list' end Rendering vanilla JavaScript In addition to using RJS with render :update, you can also just render vanilla JavaScript with :js. # Renders "alert('hello')" and sets the mime type to text/javascript render :js => "alert('hello')" Rendering with status and location headers All renders take the :status and :location options and turn them into headers. They can even be used together: render :xml => post.to_xml, :status => :created, :location => post_url(post)
发表评论
-
Destroying a Postgres DB on Heroku
2013-04-24 10:58 935heroku pg:reset DATABASE -
VIM ctags setup ack
2012-04-17 22:13 3259reference ctags --extra=+f --e ... -
alias_method_chain方法在3.1以后的替代使用方式
2012-02-04 02:14 3295alias_method_chain() 是rails里的一个 ... -
一些快速解决的问题
2012-01-19 12:35 1472问题如下: 引用Could not open library ... -
API service 安全问题
2011-12-04 08:47 1386这是一个长期关注的课题 rest api Service的 ... -
Module方法调用好不好
2011-11-20 01:58 1349以前说,用module给class加singleton方法,和 ... -
一个ajax和rails交互的例子
2011-11-19 01:53 1908首先,这里用了一个,query信息解析的包,如下 https: ... -
Rails 返回hash给javascript
2011-11-19 01:43 2277这是一个特别的,不太正统的需求, 因为,大部分时候,ajax的 ... -
关于Rubymine
2011-11-18 23:21 2267开个帖子收集有关使用上的问题 前一段时间,看到半价就买了。想 ... -
ruby中和javascript中,动态方法的创建
2011-11-18 21:01 1241class Klass def hello(*args) ... -
textmate快捷键 汇总
2011-11-16 07:20 8147TextMate 列编辑模式 按住 Alt 键,用鼠标选择要 ... -
Ruby面试系列六,面试继续面试
2011-11-15 05:55 2025刚才受到打击了,充分报漏了自己基础不扎实,不肯向虎炮等兄弟学习 ... -
说说sharding
2011-11-13 00:53 1492这个东西一面试就有人 ... -
rails面试碎碎念
2011-11-12 23:51 1946面试继续面试 又有问ru ... -
最通常的git push reject 和non-fast forward是因为
2011-11-12 23:29 17216git push To git@github.com:use ... -
Rails 自身的many to many关系 self has_many
2011-11-12 01:43 2738简单点的 #注意外键在person上people: id ... -
Rails 3下的 in place editor edit in place
2011-11-12 01:20 946第一个版本 http://code.google.com/p ... -
Heroku 的诡异问题集合
2011-11-11 07:22 1697开个Post记录,在用heroku过程中的一些诡异问题和要注意 ... -
SCSS 和 SASS 和 HAML 和CoffeeScript
2011-11-07 07:52 12960Asset Pipeline 提供了内建 ... -
Invalid gemspec because of the date format in specification
2011-11-07 02:14 2122又是这个date format的错误。 上次出错忘了,记录下 ...
相关推荐
但是,在特殊情况下,这种写死的模式无法满足需求,必须需要js的编程能力。此时,需要用render来创建HTML。 render方法的实质就是生成template模板; 通过调用一个方法来生成,而这个方法是通过render方法的参数...
**使用方法** 要使用 JsRender,首先需要在页面中引入 `jsrender.js` 或 `jsrender.min.js` 文件。然后,你可以创建一个新的模板实例,如下所示: ```javascript var tmpl = $.templates("Hello, {{:name}}!"); ``...
这个插件主要用于处理数据绑定和动态渲染,使得开发者能够在不刷新整个页面的情况下,更新网页的特定部分。 **JSRender** 是由 Microsoft 的 Dean Edwards 和 Boris Moore 开发的,它本身是一个独立的模板系统,但...
整理后的在Ruby on rails的Haml有关render_partial的用法,本资源为一张图
2. **RenderFeature生命周期**:掌握`OnEnable`,`OnDisable`,`OnExecute`等生命周期方法,知道在何时何地执行自定义的渲染逻辑。 3. **渲染队列管理**:理解如何通过`renderQueue`设置渲染顺序,以确保不同的特效...
本资料“unity关于lineRender平滑画线问题_unity3d5.3.6源码.zip”提供了一个针对这个问题的解决方案,下面将详细解析这个问题以及源码中的处理方法。 1. LineRenderer组件介绍 LineRenderer是Unity内置的组件,它...
在Vue.js框架中,`props`是父组件向子组件传递数据的一种机制,而`render`函数则是Vue中用于自定义渲染逻辑的关键工具。本文将深入探讨如何利用`props`和`render`函数来实现组件之间的动态嵌套,从而提高应用的灵活...
"htmlrender"是一个基于C#开发的HTML渲染库,它主要功能是将HTML代码转换为高质量的图像或者PDF文档,适用于需要将网页内容保存或打印的情况。这个库提供了丰富的功能,能够确保渲染出的图像或文档与原网页内容保持...
今天,我们将深入探讨 render 函数的使用方法,並探讨它在实际开发中的应用场景。 什么是 render 函数 在 Vue 中,render 函数是一个可选的函数,它可以在组件中使用,以生成 HTML 内容。render 函数的主要作用是...
在这种情况下,你需要确保在组件内部使用`shouldComponentUpdate`生命周期方法,或者使用`immer`等库进行状态管理,以确保更精确的深比较。 此外,随着React的发展,`React.PureComponent`已经被引入,它提供了类似...
在大多数情况下,当我们需要向客户端返回HTML页面时,通常会使用res.render()方法。这个方法第一个参数是要渲染的视图模板文件名,第二个参数是一个对象,包含了模板中需要用到的数据。如果模板文件位于默认的views...
JSRender是一个轻量级但功能强大的JavaScript模板引擎,它在前端项目中被广泛使用,特别是在构建动态Web应用时。这个压缩包“jsrender.zip”包含了JSRender的源码,这使得开发者可以深入了解其工作原理,并在自己的...
Python Render库还支持更多的高级特性,如纹理映射(将图像应用到物体表面)、阴影(模拟光线投射的阴影效果)、后期处理(如模糊、色彩校正等)以及同时使用多个相机视图来捕捉不同角度的场景。为了充分利用Python ...
`v-render`是基于Node.js的,Node.js是一个建立在Chrome V8引擎上的JavaScript运行环境,它以其异步I/O和事件驱动的模型而闻名,非常适合处理大量并发连接,从而在服务器端提供了高性能的解决方案。结合JavaScript的...
在这个方法中,你需要使用`DrawingContext`对象,它提供了一系列绘制基本形状、路径和图像的方法。例如: ```csharp protected override void OnRender(DrawingContext drawingContext) { drawingContext....
Unity中的Shader是实现复杂视觉效果的关键,而RenderDoc允许开发者在运行时检查和修改Shader代码,观察不同输入值对输出的影响。这对于调试Shader逻辑错误、优化Shader性能以及理解渲染流水线的工作方式非常有帮助。...
需要注意的是,不同的插件可能有不同的配置选项和使用方法,具体应参照插件的官方文档。在本例中,`ImgbigDemo`可能包含了这个示例的完整代码,包括HTML、CSS和JavaScript,你可以下载并参考其中的实现方式。 总之...
在计算机图形学中,Framebuffer Object(FBO)是OpenGL中的一种技术,用于实现"Render to Texture"(RTT)。RTT允许我们不在屏幕上...通过熟练掌握这些概念和使用方法,开发者可以在3D场景中创造出更丰富的视觉体验。
接下来,我们探讨一下laravel-pagerender的使用方法。该库通常包含一系列的辅助函数和视图组件,帮助开发者快速构建页面树。例如,它可能提供一个`renderTree()`函数,用于接收一个包含页面ID和父ID的数据集,然后...