【发布时间】:2012-04-02 07:49:28
【问题描述】:
我使用脚手架来构建我的 RoR 应用程序,然后我添加了另一个名为 apply_configs 的控制器操作。它工作正常(我添加到控制器方法的所有操作都执行得很好,我可以从服务器上的日志中看出这一点)但我无法让它在执行后呈现正确的页面。我在控制器文件的 apply_configs 方法的末尾添加了以下内容
respond_to do |format|
if @l2vpn.update_attributes(params[:l2vpn])
format.html { render action: "show", notice: 'L2vpn was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @l2vpn.errors, status: :unprocessable_entity }
end
end
在服务器上,我可以看到这些日志
Started GET "/l2vpns/apply_configs? <long list of params goes here> " for 172.24.67.151 at 2012-03-16 11:32:01 -0700
Processing by L2vpnsController#apply_configs as */*
Parameters: { <long comma separated list of params goes here> }
L2vpn Load (0.4ms) SELECT "l2vpns".* FROM "l2vpns" WHERE "l2vpns"."id" = ? LIMIT 1 [["id", 1]]
Rendered l2vpns/show.html.erb within layouts/application (1.9ms)
Completed 200 OK in 112ms (Views: 12.4ms | ActiveRecord: 1.2ms)
但实际上,与日志显示的不同,我的浏览器并没有显示show.html.erb的内容,浏览器页面没有变化。我的目标是在 apply_configs 执行后显示 show.html.erb。
任何人都知道如何实现这一点,以及为什么上面的配置对我来说没有按预期工作?
jdl 评论后的更新代码
class L2vpnsController < ApplicationController
respond_to :js, :html, :json
# GET /l2vpns/1
# GET /l2vpns/1.json
def apply_configs
@l2vpn = L2vpn.find(params[:id])
<more code goes here>
flash[:notice] = "Configs applied successfully!"
respond_with(@l2vpn, :location => l2vpns_url)
end
<other controller action definitions go here>
end
【问题讨论】:
标签: ruby-on-rails ruby methods controller rendering