开发者

issue integrating flex with ruby on rails

I'm having an issue integrating flex with ruby on rails. I get this error:

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
  <internal:prelude>:8:in `synchronize'
  /Users/tammam56/.rvm/rubies/ruby-1.9.1-p378/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /Users/tammam56/.rvm/rubies/ruby-1.9.1-p378/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /Us开发者_C百科ers/tammam56/.rvm/rubies/ruby-1.9.1-p378/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

I believe Rails automatically generate an AuthenticityToken when using "View" components that generates the HTML as I notice in the console AuthenticityToken gets passed with every request. But When I'm using Flex as my client interface instead of HTML generated by view how do I get/generate this AuthenticityToken and store it in Flex.

Thanks,

Tam


Hey, great question. This was actually a pretty tough problem to solve, but Dima and contributors from RestfulX have solved it quite nicely.

In short, you have to store the authenticity token in Flex after the first request Flex makes to Rails, right when everything starts up. Then you pass it back with every request from Flex to Rails. To get the request, RestfulX has an initializer script that gets in there with the Rack middleware to send the authenticity token to Rails.

I suggest checking out the RestfulX Google Group, and checking out the sample Pomodo on Rails application (RestfulX integrating Flex and Rails). It's a serious Project Management Flex app with an Admin system, so check out the code for all that authentication stuff.

It was built off a script like this one:

FlashSessionCookieMiddleware

And here's a tutorial explaining file uploads between Flex and Rails, which have a lot of issues with authenticity tokens.

Let me know how it goes! Lance


I'm not a flex specialist but here is how you store in a js variable:

window._token = '<%= form_authenticity_token %>'; 


There's a blog post on it that describes all the steps in how to do it.

See at:

http://blog.dt.org/index.php/2008/06/rails-2-flex-3-and-form-authenticity-tokens/

Hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜