user478798
user478798

Reputation: 301

Rails redirect_to another controller method throwing "Template missing"

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 shorturl 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.

Upvotes: 2

Views: 4758

Answers (1)

Mohit Jain
Mohit Jain

Reputation: 43939

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.

Upvotes: 2

Related Questions