# Begore\_filter and XHR/Ajax calls

**URL:** <https://www.ruby-forum.com/t/begore-filter-and-xhr-ajax-calls/119276>\
**Category:** Rails\
**Created:** [November 5, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/begore-filter-and-xhr-ajax-calls/119276 "2007-11-05T18:42:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [November 5, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/begore-filter-and-xhr-ajax-calls/119276/1 "2007-11-05T18:42:42Z")

</div>

What’s the best way to do a javascript alert warning when someone is  
trying to access a ajax method that requires authentication - for  
example to rate a recipe, I have a star-based ajax/css interface. To  
actually add a rating you need to be logged in. When I use the  
before\_filter, it just redirects to the login page - I’d like to show  
an alert that says something like “to add a rating, please register/  
login first” right there - what’s the best way to do this?

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [November 5, 2007, 6:50pm UTC](https://www.ruby-forum.com/t/begore-filter-and-xhr-ajax-calls/119276/2 "2007-11-05T18:50:53Z")

</div>

On 5 Nov 2007, at 17:41, raghus wrote:

> What’s the best way to do a javascript alert warning when someone is  
> trying to access a ajax method that requires authentication - for  
> example to rate a recipe, I have a star-based ajax/css interface. To  
> actually add a rating you need to be logged in. When I use the  
> before\_filter, it just redirects to the login page - I’d like to show  
> an alert that says something like “to add a rating, please register/  
> login first” right there - what’s the best way to do this?

Your before\_filter stuff is just regular code. It can do a  
render :update for example just as easily as it does a redirect.

Fred

---

<div class="post-metadata">

**Author:** ![raghus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@raghus](https://www.ruby-forum.com/u/raghus)\
**Post date:** [November 5, 2007, 7:34pm UTC](https://www.ruby-forum.com/t/begore-filter-and-xhr-ajax-calls/119276/3 "2007-11-05T19:34:14Z")

</div>

That was a helpful answer - thanks Fred.

On Nov 5, 9:49 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
