2
votes

I'm using Uploadify 3.1 with Rails 3.2.2. I use Authlogic to deal with authentication. Authlogic provides a current_user method which gives the user which made the request.

When I try to upload some file with Uploadify 3.1, current_user is not set when looked for in an action, it gives nil. This did not happen with the Uploadify 2.1.4. Here is how I'm calling uploadify:

jQuery('#something').uploadify({

      uploader        : '#{some_path_from_rails_routes}',
      swf             : '/uploadify/uploadify.swf',
      cancelImg       : '/uploadify/cancel.png',
      fileTypeDesc    : 'FileNames',
      auto            : true,
      removeCompleted : false,
      buttonText      : 'Some Label',
      formData        : {
        '_http_accept': 'application/javascript',
        '#{session_key_name}' : encodeURIComponent('#{u(cookies[session_key_name])}'),
        'authenticity_token'  : encodeURIComponent('#{u(form_authenticity_token)}'),
      }
});

Any thoughts? Thanks!

1

1 Answers

0
votes

Uploadify's flash component uses a different cookie storage than the one Rails uses for its sessions. You can use the flash_cookie_session gem to work around this problem.

From its documentation, it looks like you will need to modify your formData to something like this:

{
  "<%= key = Rails.application.config.session_options[:key] %>" : "<%= cookies[key] %>"
  "<%= request_forgery_protection_token %>" : "<%= form_authenticity_token %>",
}