I’m attempting to upload an image via ajax using paperclip.
I’m using the qqfileuploader for the ajax stuff and it doesn’t seem to have an option where I can define the parameter name for the post request.
The parameters sent from the ajax post are
qqfile=filename.jpg
so in my model, I have aliased qqfile to photo
alias_attribute :qqfile, :photo has_attached_file :photo attr_accessible :title, :photo
when I upload a file via ajax, I get the following errors
Parameters: {"qqfile"=>"Penguins.jpg"}
WARNING: Can't verify CSRF token authenticity
Creating scope :page. Overwriting existing method User.page.
User Load (1.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Creating scope :page. Overwriting existing method RoleUser.page.
Creating scope :page. Overwriting existing method Role.page.
Role Load (1.4ms) SELECT `roles`.* FROM `roles` INNER JOIN `role_users` ON `roles`.`id` = `role_users`.`role_id` WHERE `role_users`.`user_id` = 1
SQL (0.7ms) BEGIN
Creating scope :page. Overwriting existing method Task.page.
[paperclip] Duplicate URL for photo with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Recipe class
I’m not sure if the CSRF token will be an issue, there is a token on the page, so maybe I just need to be sending that, I assume I can get it is a variable with javascript?
But what is the deal with the duplicate url??? Am I not aliasing correctly? Can I not alias a paperclip object for some reason?
my controller is also very simple
def create
@recipe = Recipe.new(params[:recipe])
@recipe.author_id=current_user.id
if @recipe.save
return render :json => @recipe
else
return render :text => 'an error occured saving the recipe'
end
end
Rails generates a security token for POST events based on the user’s session. If that token is missing or doesn’t match what’s expected, the session will be reset. See this:
http://guides.rubyonrails.org/security.html#csrf-countermeasures
As for the duplicate URL, are you sure your URL pattern is specific enough? It looks to me that if you upload a file with the same name for the same model instance you’d have a problem. It would help to see your controller code.