Rails redirect_to 另一个控制器方法抛出“模板丢失" [英] Rails redirect_to another controller method throwing "Template missing"

查看:40
本文介绍了Rails redirect_to 另一个控制器方法抛出“模板丢失"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一定错过了一些东西.我有一个用于短网址的控制器操作:

I gotta be missing something. I have a controller action for short urls:

def shorturl
   redirect_to :action => show, :id => Base58.decode(params[:id]) and return
end

我的意图是重定向或加载同一控制器的常规显示方法.在这一点上,我不在乎哪种方式,只想先让它工作.

My intention is have this either redirect or load the regular show method of the same controller. At this point, I don't care which way, just want to get it working first.

问题是它抛出了一个缺少模板的错误,比如它没有退出 shorturl 方法.

The problem is it throws a missing template error like its not exiting the shorturl method.

Missing template controller/shorturl with {:locale=>[:en, :en], :formats=>[:html], :handlers=>[:rhtml, :rxml, :builder, :erb, :rjs]} 

控制台显示来自 show 的查询正在执行,因此它似乎在执行重定向,但仍停留在方法内并期望看到 shorturl 而不是重定向方法的视图.

The console shows the query from show is executing so it seems its doing the redirect but still staying inside the method and expecting a view for shorturl instead of the redirected method.

推荐答案

打开你的终端,进入项目目录并输入

open your terminal, and go to project directory and type

   rake routes

会让你知道从你的路由文件生成的各种路径.

Will let you know about the various paths generated from your routes file.

然后使用

redirect_to xyz_path(:id=> Base58.decode(params[:id]))
return

--

重定向和渲染太不同了.

redirect and render are too different things.

redirect_to(:action=>’my_action’)

将向您的浏览器发送 302 重定向请求,结果是所有现有变量都丢失 [2],并且将执行名为my_action"的操作.

will send a 302 redirect request to your browser, the consequence being that any existing variables are lost [2], and the action called ‘my_action’ will be executed.

render(:action=>’my_action’)

不会执行名为my_action"[1] 的操作中的代码.它只会渲染视图.现有变量不会丢失.

will NOT execute the code in the action called ‘my_action’ [1]. It will render the view only. Existing variables will not be lost.

这篇关于Rails redirect_to 另一个控制器方法抛出“模板丢失"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆