Coder Social home page Coder Social logo

Image Upload about stories HOT 1 OPEN

hibiken avatar hibiken commented on September 16, 2024
Image Upload

from stories.

Comments (1)

AjayBarot avatar AjayBarot commented on September 16, 2024

@blueiconingenieria : Open this view views/users/edit.html.erb
see this code.

<label class="change-avatar" id="change-avatar" style="background-image: url('<%= @user.avatar.url %>')">
  <%= f.file_field :avatar %>
  <%= icon('camera') %>
</label>

This will generate html for file upload
Note: Don't forget to add html: { multipart: true } in form.

Now see this code at edit_profile.js

$("#user_avatar").change(function(){
   ProfileEdit.readURL(this);
});

after selection of image by user from the image selection window this change event of jquery will execute.
and manipulate $('#change-avatar') style via help of jquery.

After the form submit rails controller will receive this kind of parameter of file.

"user"=>{"description"=>"", "location"=>"", "avatar"=>#<ActionDispatch::Http::UploadedFile:0x007fa419a1cda8 @tempfile=#<Tempfile:/var/folders/y_/32g4l1rs20g9tnm8pllbysf00000gn/T/RackMultipart20170323-2144-1xz74o4.svg>, @original_filename="stories-logo.svg", @content_type="image/svg+xml", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"stories-logo.svg\"\r\nContent-Type: image/svg+xml\r\n">}

and thus user profile image will saved in database. and user's profile pic will not saved automatically unless you clicked save change button.

Let me know If you still have a question or doubt into this functionality.

from stories.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.