编辑操作中没有respond_to阻止(使用脚手架生成)?

时间:2021-12-08 01:20:34

Does anyone know why there is no respond_to block for generated edit actions? Every other action in typical scaffold controllers has a respond_to block in order to output html and xml formats. Why is the edit action an exception?

有谁知道为什么生成的编辑操作没有respond_to块?典型脚手架控制器中的每个其他操作都有一个respond_to块,以便输出html和xml格式。为什么编辑操作是例外?

I'm using the latest version of Ruby on Rails (2.1.1).

我正在使用最新版本的Ruby on Rails(2.1.1)。

3 个解决方案

#1


12  

Rails handles the 99% case: It's fairly unlikely you'd ever need to do any XML or JSON translations in your Edit action, because non-visually, the Edit action is pretty much just like the Show action. Nonvisual clients that want to update a model in your application can call the controller this way

Rails处理99%的情况:你很可能不需要在Edit操作中进行任何XML或JSON翻译,因为非直观地,Edit操作就像Show动作一样。想要更新应用程序中的模型的非可视客户端可以通过这种方式调用控制器

GET /my_models/[:id].xml (Show) 

Then, the client app can make any transformations or edits and post (or put) the results to

然后,客户端应用程序可以进行任何转换或编辑,并将结果发布(或放入)

PUT /my_models/[:id].xml (Update) 

When you call this, you usually are doing it to get an editable form of the Show action:

当你调用它时,你通常会这样做以获得Show动作的可编辑形式:

GET /my_models/[:id]/edit 

And it is intended for human use. 99% of the time, that is. Since it's unusual to transform the data in the Edit action, Rails assumes you aren't going to, and DRYs up your code by leaving respond_to out of the scaffold.

它适用于人类。 99%的时间,即。由于在编辑操作中转换数据是不常见的,因此Rails假定您不会这样做,并通过将respond_to从scaffold中删除来干掉您的代码。

#2


2  

Somewhat related. Some may wonder why the rails scaffolding for the new action still has a respond_to block; whereas the edit action does not. This is because a request to something like:

有点相关。有些人可能想知道为什么新动作的rails scaffolding仍然有一个respond_to块;而编辑动作却没有。这是因为对以下内容的请求:

GET /my_models/new.xml

...gives back an XML template that can be used to create a new model.

...返回一个可用于创建新模型的XML模板。

#3


1  

Because the edit action will only be called from HTML There is no need for the edit form to be returned in an XML context. Using REST, you simply make a put call directly to update with the relevant information.

因为只能从HTML调用编辑操作所以不需要在XML上下文中返回编辑表单。使用REST,您只需直接拨打电话,即可使用相关信息进行更新。

#1


12  

Rails handles the 99% case: It's fairly unlikely you'd ever need to do any XML or JSON translations in your Edit action, because non-visually, the Edit action is pretty much just like the Show action. Nonvisual clients that want to update a model in your application can call the controller this way

Rails处理99%的情况:你很可能不需要在Edit操作中进行任何XML或JSON翻译,因为非直观地,Edit操作就像Show动作一样。想要更新应用程序中的模型的非可视客户端可以通过这种方式调用控制器

GET /my_models/[:id].xml (Show) 

Then, the client app can make any transformations or edits and post (or put) the results to

然后,客户端应用程序可以进行任何转换或编辑,并将结果发布(或放入)

PUT /my_models/[:id].xml (Update) 

When you call this, you usually are doing it to get an editable form of the Show action:

当你调用它时,你通常会这样做以获得Show动作的可编辑形式:

GET /my_models/[:id]/edit 

And it is intended for human use. 99% of the time, that is. Since it's unusual to transform the data in the Edit action, Rails assumes you aren't going to, and DRYs up your code by leaving respond_to out of the scaffold.

它适用于人类。 99%的时间,即。由于在编辑操作中转换数据是不常见的,因此Rails假定您不会这样做,并通过将respond_to从scaffold中删除来干掉您的代码。

#2


2  

Somewhat related. Some may wonder why the rails scaffolding for the new action still has a respond_to block; whereas the edit action does not. This is because a request to something like:

有点相关。有些人可能想知道为什么新动作的rails scaffolding仍然有一个respond_to块;而编辑动作却没有。这是因为对以下内容的请求:

GET /my_models/new.xml

...gives back an XML template that can be used to create a new model.

...返回一个可用于创建新模型的XML模板。

#3


1  

Because the edit action will only be called from HTML There is no need for the edit form to be returned in an XML context. Using REST, you simply make a put call directly to update with the relevant information.

因为只能从HTML调用编辑操作所以不需要在XML上下文中返回编辑表单。使用REST,您只需直接拨打电话,即可使用相关信息进行更新。