I am sending a javascript request to a controller action to try redirecting to another html page if certain conditions are not met. After looking at a few questions, here's what I came up with:
def twittertweet
if current_user && current_user.twitter_token
....
else
flash[:notice] = "You must be registered with Twitter to do that."
respond_to do |format|
format.js { render(:update) { |page| page.redirect_to authentications_url } }
end
end
end
I want to redirect to authentications_url. However, this happens:
Started POST "/twittertweet.json" for 127.0.0.1 at 2012-04-11 13:38:27 -0400
Processing by ItemsController
Parameters: {"id"=>"22"}
Category Load (0.3ms) SELECT "categories".* FROM "categories"
Rendered items/update.html.erb within layouts/application (0.0ms)
Completed 200 OK in 112ms (Views: 79.9ms | ActiveRecord: 5.7ms)
As you can see, it just does not try to redirect to url_authentication. However, I know that the "else" statement is being achieved (I put puts instructions to help me find this).
Any workarounds for this?
Update
If you try the DanS solution, there will be a MissingTemplateError. It is still trying to redirect to # update elements:
ActionView::MissingTemplate (Missing template items/update, application/update with {:handlers=>[:erb, :builder, :coffee], :formats=>[:json], :locale=>[:en, :en]}. Searched in:
* "/Users/dylandrop/Documents/givespend/app/views"
* "/Users/dylandrop/.rvm/gems/ruby-1.9.2-p290/gems/devise-2.0.4/app/views"
):