我可以有一个运行多个方法的操作吗?
假设我的控制器中有这个:
def something
end
def email
end
def house
end
我想创建一个操作来运行所有操作,例如电子邮件和房屋,
def runall
Run email, something and house
end
它是如何完成的?
Lets say I have this in my controller:
def something
end
def email
end
def house
end
I want to create an action that runs all of the action something, email and house
def runall
Run email, something and house
end
How is it done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Object#send
这一切都假设这些是某种私人助手,而不是调用来呈现视图等的实际控制器操作。否则我不建议这样做。
Using Object#send
This is all assuming these are some sort of private helpers, rather than actual controller actions that are called to render a view etc. Otherwise I don't suggest doing this.
只是为了词汇的缘故:
您对以下问题有很好的答案:“我可以有一个运行多个方法的操作吗”
一个操作链接到一个视图,因此一次执行多个操作是没有意义的
Just for vocabulary's sake:
you've had great answers to the following question: "can I have an action which runs several methods"
an action is linked to a view so it's non-sense to execute several actions at once