rails 中怎么使用 union

直接用find_by_sql返回的是数组,没办法用will_paginate进行分页。rails有没有union的操作,返回record对象... 直接用find_by_sql返回的是数组,没办法用will_paginate进行分页。rails有没有union的操作,返回record对象 展开
 我来答
匿名用户
2015-11-04
展开全部
render 先上点搜集的常用方式

1.render :action => "long_goal", :layout => "spectacular"
2.render :partial => "person", :locals => { :name => "david" }
3.render :template => "weblog/show", :locals => {:customer => Customer.new}
4.render :file => "c:/path/to/some/template.erb", :layout => true, :status => 404
5.render :text => "Hi there!", :layout => "special"
6.render :text => proc { |response, output| output.write("Hello from code!") }
7.render :xml => {:name => "David"}.to_xml
8.render :json => {:name => "David"}.to_json, :callback => 'show'
9.render :inline => "<%= 'hello ' + name %>", :locals => { :name => "david" }
10.render :js => "alert('hello')"
11.render :xml => post.to_xml, :status => :created, :location => post_url(post)
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)

例如 <%= render 'form' %> 就是 跳转到 _form.html.erb文件

1:render(:text => string) 2:render(:inline => string, 3:[:type => "rhtml"|"rxml"]) 4:render(:action => action_name) 5:render(:file => path, 6:[:use_full_path => true|false]) 7:render(:template => name) 8:render(:partial => name) 9:render(:nothing=>true) 10:render()

第1行:直接渲染出文本 第2行:把传入的string渲染成模板(rhtml或者rxml) 第3行:直接调用某个action的模板,相当于forward到一个view 第4行:使用某个模板文件render, 当use_full_path参数为true时可以传入相对路径 第5行:使用模板名render,e.x.: render(:template => "blog/short_list") 第6行:以局部模板渲染 第7行:什么也不输出,包括layout 第8行:默认的的render, 相当于render(:action => self)

查了render的源码,粘贴出来如下:

1.Renders the content that will be returned to the browser as the response body.
2.Rendering an action
3.
4.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).
5.
6. # Renders the templa www.hnnedu.com te for the action "goal" within the current controller
7. render :action => "goal"
8.
9. # Renders the template for the action "short_goal" within the current controller,
10. # but without the current active layout
11. render :action => "short_goal", :layout => false
12.
13. # Renders the template for the action "long_goal" within the current controller,
14. # but with a custom layout
15. render :action => "long_goal", :layout => "spectacular"
16.
17.Rendering partials
18.
19.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) andwhen sub-page updates happen (from the controller action responding to Ajax calls). By default, the current layout is not used.
20.
21. # Renders the same partial with a local variable.
22. render :partial => "person", :locals => { :name => "david" }
23.
24. # Renders the partial, making @new_person available through
25. # the local variable 'person'
26. render :partial => "person", :object => @new_person
27.
28. # Renders a collection of the same partial by making each element
29. # of @winners available through the local variable "person" as it
30. # builds the complete response.
31. render :partial => "person", :collection => @winners
32.
33. # Renders a collection of partials but with a custom local variable name
34. render :partial => "admin_person", :collection => @winners, :as => :person
35.
36. # Renders the same collection of partials, but also renders the
37. # person_divider partial between each person partial.
38. render :partial => "person", :collection => @winners, :spacer_template => "person_divider"
39.
40. # Renders a collection of partials located in a view subfolder
41. # outside of our current controller. In this example we will be
42. # rendering app/views/shared/_note.r(html|xml) Inside the partial
43. # each element of @new_notes is available as the local var "note".
44. render :partial => "shared/note", :collection => @new_notes
45.
46. # Renders the partial with a status code of 500 (internal error).
47. render :partial => "broken", :status => 500
48.
49.Note that the partial filename must also be a valid Ruby variable name, so e.g. 2005 and register-user are invalid.
50.Automatic etagging
51.
52.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.
53.Rendering a template
54.
55.Template rendering works just like action rendering except that it takes a path relative to the template root. The current layout is automatically applied.
56.
57. # Renders the template located in [TEMPLATE_ROOT]/weblog/show.r(html|xml) (in Rails, app/views/weblog/show.erb)
58. render :template => "weblog/show"
59.
60. # Renders the template with a local variable
61. render :template => "weblog/show", :locals => {:customer => Customer.new}
62.
63.Rendering a file
64.
65.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.
66.
67. # Renders the template located at the absolute filesystem path
68. render :file => "/path/to/some/template.erb"
69. render :file => "c:/path/to/some/template.erb"
70.
71. # Renders a template within the current layout, and with a 404 status code
72. render :file => "/path/to/some/template.erb", :layout => true, :status => 404
73. render :file => "c:/path/to/some/template
追问
你这是答非所问啊,我问的是rails中union的用法
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式