If you are using jQuery see this post.
To set focus on first text field with Prototype I prefer something like this
var firstField = $$('input:text:visible').first();
if (firstField)
firstField.focus();
but you can also try with Form.focusFirstElement or Form.findFirstElement
3RAWXQXCQDMZ
focus, form, JavaScript, Prototype, selectors
Rails protects controller actions from CSRF (Cross-Site Request Forgery) attacks with a token based on a random string stored in the session. The token parameter is named authenticity_token by default and will be embedded in all forms and Ajax requests generated by Rails.
You should also add this token to all Ajax request that you hand coded. As suggested in Rails documentation you can add this line in head section.
<%= javascript_tag "window._token = '#{form_authenticity_token}'" %>
and then add authenticity_token to parameters option of Ajax requests
new Ajax.Request('/some/url', {
parameters: "foo=bar&authenticity_token="+_token
});
Remote forgery protection plugin
This can get tedious if you have a lot of Ajax requests so I wrote a simple plugin that adds authenticity token to all Ajax requests automatically.
You can install it with
script/plugin install git://github.com/vlado/remote_forgery_protection.git
Now all you have to do is add this line inside head section of you’re layout
<%= remote_forgery_protection %>
and all non GET Ajax request will have authenticity_token parameter automatically included.
Read the rest of this entry
ajax, authentication, csrf, extjs, forgery, jQuery, plugin, protection, Prototype, Rails, token
I am working on extension for Radiant CMS. I wanted to disable caching for development, but wasn’t able to find right method for this, so finally I did it by putting this into my extensions activate method
if RAILS_ENV=="development"
Page.class_eval {
def cache?
false
end
}
end
This is more of a hack then a real solution, so please use comments to point me in the right direction. I’m using Radiant version 0.8.1.