简体   繁体   English

我可以在 rails 的单个页面中呈现两个不同的控制器操作吗

[英]Can i render two different controller actions in a single page in rails

在此处输入图片说明

So basically what I am about to do is have a fixed search bar with is results.所以基本上我要做的是有一个固定的搜索栏和结果。 And also view page of the selected result with links to all its CRUD actions, and also link to move to other associated controllers.并且还查看所选结果的页面,其中包含指向其所有 CRUD 操作的链接,以及移动到其他关联控制器的链接。

Now when I click on edit action or if I choose to move to another associated controller view the search bar and its results should be unchanged.现在,当我单击编辑操作或选择移动到另一个关联的控制器时,搜索栏及其结果应该保持不变。 I have a basic understanding of jquery and ajax, would I need to try angular.js for this.我对 jquery 和 ajax 有基本的了解,我是否需要为此尝试 angular.js。

So to summarize I need a fixed search bar with search results unaffected on moving from one controller to other.所以总而言之,我需要一个固定的搜索栏,搜索结果从一个控制器移动到另一个控制器不受影响。

Please help me figure this out.请帮我解决这个问题。 If you have trouble understanding the question leave a comment.如果您在理解问题时遇到困难,请发表评论。

If you want to render two (or more) variables in a controller you may do something wrong.如果您想在控制器中呈现两个(或更多)变量,您可能会做错事。

I see several options here.我在这里看到了几个选项。

  1. You probably should have a page, when you already have a static bar but have nothing under it though.你可能应该有一个页面,当你已经有一个静态栏但它下面什么都没有。 In that case, you simply call a controller for this bar and nothing more.在这种情况下,您只需为此栏调用控制器即可。 Then you use ajax to render what's inside second 'frame'.然后使用 ajax 渲染第二个“框架”内的内容。
  2. You probably will want to take a look at Facade pattern .您可能想看看Facade 模式 It allows you to instantiate only one variable in a controller at a time.它允许您一次仅实例化控制器中的一个变量。 Also, it may somehow structurize things in your head, and you will see more pleasant ways.此外,它可能会以某种方式将您头脑中的事物结构化,并且您会看到更愉快的方式。

(Also read this . It has a slight example of Facade with Rails) (另请阅读 这篇文章。它有一个 Facade with Rails 的小例子)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一页,两种模式(2种不同的操作) - One Page, Two Modals (2 different actions) 如何使用jQuery在Rails 4中基于click事件呈现不同的UJS动作 - How to render different UJS actions based on the click event in Rails 4 with jQuery 一键调用两种不同的控制器方法(动作) - Calling two different controller methods(actions) on one button click 如何在没有原型助手的情况下从rails控制器渲染局部页面 - How to render partial in page from rails controller without prototype helpers 使用jQuery在Rails中使用另一个控制器呈现页面上的部分表单 - Render partial form on page with another controller in Rails with jQuery 如何通过执行不同操作的Google按钮获得两次登录? - How can I get two Sign-in with Google buttons executing different actions? 如何在一个页面上有两个不同的变量? (JQuery的) - How can I have two of these on one page with different variables? (JQuery) 如何将具有两个提交按钮的表单提交给Grails中的两个不同的控制器操作 - How to submit the form having two submit buttons to two different controller actions in grails 两个人在一个按钮中提交动作 - Two submits actions in a single button Rails渲染不会刷新页面 - Rails render not refrshing the page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM