Plugin: validate_request

July 26, 2006 at 5:28 am Leave a comment

A very useful plugin by Scott A. Woods.

validate_request plugin allows us to check the request method and parameters that are used to call your action.

For Example consider an add_to_cart action as:


  def add_to_cart
    @product = Product.find(params[:id])
    @cart.add_product(@product)
  end

The link to add an item to our cart should like store/add_to_cart/nnn, where nnn is an integer. There will be an error if some one intentionaly enter store/add_to_cart/some_string_here.
ValidateRequest allows us to double check these things, and act appropriately. For instance, we could solve the above problem by adding one line to our action:


  def add_to_cart
    validate_request(:get, :id => :integer) or return
    @product = Product.find(params[:id])
    @cart.add_product(@product)
  end

The validate_request method will now verify that incoming requests are via the GET method, and that they contain one argument called ‘id’ whose value is an integer. If any of these conditions aren’t true, the requester is redirected to the site’s home page (configurable, of course), and flash[:error] is set with a polite message (also configurable).

Install the plugin by running the following commands from your rails application’s directory:

./script/plugin source svn://rubyforge.org//var/svn/validaterequest/plugins ./script/plugin install validate_request

For more details visit http://rubyforge.org/projects/validaterequest/

Entry filed under: rails, rails plugins, Ruby, RubyonRails. Tags: .

Plugin: tabnav Make ids in URL Search engine friendly

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Important Notice…

I have moved this blog to http://webonrails.com . I will continue posting at http://webonrails.com, not on https://webonrails.wordpress.com.

Kindly update your book marks to http://webonrails.com

and http://webonrails.com/feed .

I am really very sorry for inconvenience.

Comming Soon….

Domain for Sale

TheRailsHosting.com


(Contact me)

Recent Posts

Calender

July 2006
M T W T F S S
« Jun   Aug »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Subscribe

  • Add to Google
  • Subscribe in NewsGator Online
  • Subscribe with Bloglines
  • WebOnRails on feedburner
  • technorati

del.icio.us

Feeds

Flickr Photos

A bellezza di a natura (C☺rsica)

JWL5932 Mountain Hare..

Black and Gold

More Photos

Visitor’s Location

Blog Stats

  • 17,978 hits

%d bloggers like this: