[英]Rails controller methods
I have a controller action that is calling a model method to render some data. 我有一个控制器操作,正在调用模型方法来呈现一些数据。 The controller looks something like this 控制器看起来像这样
class WeekController < ApplicationController
def index
@week = Week.first
end
def render
Week.render
redirect_to root_url
end
end
Currently my Week.render method has a bug in it and is causing errors. 目前,我的Week.render方法中存在错误,并导致错误。 Which is fine, however when I am calling my index action the page fails because of the error in my render action. 很好,但是当我调用索引动作时,页面由于渲染动作中的错误而失败。
Is it normal for rails to call actions other than the one being called or is there something weird going on? Rails调用被调用的动作以外的其他动作是正常的吗,还是发生了一些奇怪的事情?
It is ok to call other actions as long as you don't call redirect_to
or render
multiple times in a response. 只要您不调用redirect_to
或在响应中多次render
,就可以调用其他操作。
By the way render
is a reserved word, and you should not use it for a custom method. 顺便说一句render
是一个保留字,你不应该使用它的自定义方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.