[英]rails: multiple controller actions on one page
i got a simple rails app for browser bookmarks. 我有一个用于浏览器书签的简单Rails应用。
image here 图片在这里
a bookmark, seen on the top, is a folder that contains the subcategory folders in the left sidebar. 书签(在顶部显示)是一个文件夹,在左侧边栏中包含子类别文件夹。
when clicking a folder on the left one gets the bookmarks listing of the folder. 单击左侧的文件夹时,将获得该文件夹的书签列表。 ie a bookmarks#index with params. 即带参数的bookmarks#index。 same is folder#index with params on the left and top. 相同的是folder#index,左侧和顶部带有参数。 how can i render all the 3 controller action on one page? 如何在一页上呈现所有3个控制器的动作?
Well you can definitely render to a common page from different actions, see the example:- in bookmarks_controller.rb
好吧,您可以肯定地可以通过不同的操作呈现到公共页面,请参见示例:-在bookmarks_controller.rb
def index
#do your stuffs
render "path_of_comman_page",locals: {x: "foo", y: "bar"}
end
in folder_controller.rb
在folder_controller.rb
def index
#do your stuffs
render "path_of_comman_page",locals: {x: "foo", y: "bar"}
end
So here by you will be able to access all locals variable at your comman page. 这样,您就可以在comman页面上访问所有locals变量。 like x, y
path_of_comman_page can be for example /bookmarks/listings
which means you are rendering data to bookmarks controller listings.html.erb
像x, y
一样x, y
path_of_comman_page可以是例如/bookmarks/listings
,这意味着您正在将数据呈现到bookmarks controller listings.html.erb
Alternative it can be done by common partial for example 替代地,它可以通过例如通用的部分来完成
def index
#do your stuffs...
respond_to do |format|
format.html { render partial: "listings/listing", locals: {x: "foo", y: "bar"}}
end
end
actually i want it like this, somehow with js. 其实我想要这样,用js。 maybe it's possible with a controller too ... folders/index.haml 也许也可以使用控制器... folder / index.haml
.container_top
- @folders.each do |f|
- if f.is_rootparent?
-# send ajax to fetch subcategory folders!
=link_to folder_path(parent: f), remote: true do
.bookmark_vertical
%p = f.title
.container_left
#appendsubcategoryfoldershere
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.