-
-
Save seebq/38110 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# Paperclip | |
has_attached_file :photo, | |
:styles => { | |
:thumb=> "100x100#", | |
:small => "150x150>", | |
:medium => "300x300>", | |
:large => "400x400>" } | |
This is the method for where the user uploads the photo: | |
# normally we use all lowercase for methods just fyi: | |
# ex: def photo_upload | |
# | |
# Also, now this method needs to be submitted with a :id parameter: | |
# so you'd have the form post to this URL: | |
# | |
# /your_controller/photoUpload/69 | |
# | |
# And this would send the photo up for user with id 69, see: | |
# | |
def photoUpload | |
@user = User.find(params[:id]) | |
end | |
And this is the view for uploading that photo: | |
<%= error_messages_for :photo %> | |
<% form_for(@user,:html => { :multipart => true }) do |f| %> | |
<%= f.error_messages %> | |
<p> | |
<%= f.label 'Photo' %><br /> | |
<%= f.file_field :photo %> | |
</p> | |
<p> | |
<%= submit_tag 'Upload' %> | |
</p> | |
<% end -%> | |
# This form will generate a form field that will post to the | |
# UserController, and will most likely be trying to create a user. Why don't you use | |
# the normal form tag instead of trying to use the form_for -- it's only good | |
# for RESTful, straight up, CRUD operations (the basic create, read, update, delete actions). | |
# | |
# how about instead: | |
<%= error_messages_for :photo %> | |
<% form_tag("/users/photoUpload/#{@user.id}", :html => { :multipart => true }) do %> | |
<p> | |
<%= label_tag 'Photo' %><br /> | |
<%= file_field_tag 'photo' %> | |
</p> | |
<p> | |
<%= submit_tag 'Upload' %> | |
</p> | |
<% end -%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment