[英]How can I perform another action of another controller (rendering too) in Rails 2.3.5 without a redirect?
I know that it's totally against the MVC, but anyway it must be done that way. 我知道这完全违反了MVC,但是无论如何都必须这样做。 So I need something like that: 所以我需要这样的东西:
app/controllers/controller_a.rb
class ControllerA < ApplicationController
def index
some_code
end
end
app/controllers/controller_b.rb
class ControllerB < ApplicationController
def other_index
@var = 'example'
end
end
app/views/controller_b/other_index.html.erb
<%= @var %>
So, when I visit the URL localhost:3000/controller_as/index (I mean, the one that corresponds the index action of controller_a.rb) I must obtain the next in my browser: 因此,当我访问URL localhost:3000 / controller_as / index(我的意思是,对应于controller_a.rb的索引操作的URL)时,我必须在浏览器中获取下一个:
example
I mean, I must perform controller_b other_index action and render other_index.html.erb 我的意思是,我必须执行controller_b other_index动作并呈现other_index.html.erb
I'll appreciate any help. 我将不胜感激。 Thanks. 谢谢。
You need to refactor the logic of controller_b into the model. 您需要将controller_b的逻辑重构到模型中。 Alternative would be to use AJAX to call controller_b from the index page of controller_a 替代方法是使用AJAX从controller_a的索引页调用controller_b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.