Thursday, February 5, 2009

Working on Webserver Layer

I was getting an "InvalidAuthenticityToken" exception when trying to post to my end point for the rating widget. I found a thread with Google on Ruby Forum that I think will help.

I thought the webserver was supposed to return json from /ratesubmit, but really it just returns a number, which is the rating.

For some reason, my rating seems to work, but when I reload the page, it doesn't seem to persist. I've tried posting to the reference app server and the load balanced app server.

To get things in config/initializers to work, restarting WEBrick is helpful.

POSTing a file in ruby is a fun challenge:
http://stackoverflow.com/questions/184178/ruby-how-to-post-a-file-via-http-as-multipartform-data
http://snippets.dzone.com/posts/show/5165
http://curb.rubyforge.org/

Couldn't get curb or rest_client to work..

1 comment:

Bracken said...

If you're still having problems with the file post, you should look into 'rest-client' Here is all you need to do:
Install gem:
gem install rest-client

Code:
require 'rest_client'
file = File.new(file_path)
url = "http://www.something.com/"
RestClient.post url, :image => file, :submituser => "whatever", etc...

Since 'file' is a file object, it takes care of everything for you. Nice and easy. ;)