开发者

Rails redirect_to another controller method throwing "Template missing"

开发者 https://www.devze.com 2023-03-03 09:27 出处:网络
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

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.

The problem is it throws a missing template error like its not exiting the s开发者_高级运维horturl method.

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

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.

then redirect using

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

Edit:--

redirect and render are too different things.

redirect_to(:action=>’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’)

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

0

精彩评论

暂无评论...
验证码 换一张
取 消