1

So, I'm using carrier wave to allow users to upload profile images. Now ultimately, I'd like the user to be able to click on the image and upload a new one on the fly in the profile.html.haml page.

So, I've tried the below adding a form with a put action to let the user update the image on the fly without having to go to the edit.html.haml page.

However, I'm being hit with this error:

Could not find a valid mapping for nil

Extracted source (around line #8):




<%= form_for(@user, :url => registration_path(@user), :html => { :method => :put }, :html => {:multipart => true}) do |f| %>
<%= link_to (image_tag current_user.profile_image_url(:thumb).to_s), edit_account_path(current_user)%>
<% end %>

Where did I go wrong?

Alternatively I've tried this which might be totally off:

 <%= link_to (image_tag current_user.profile_image_url(:thumb).to_s), f.file_field :profile_image%>     

which gave this error:

Sites/Friendiose-master/app/views/home/landing_welcome.html.erb:9: syntax error, unexpected tSYMBEG, expecting ')'
...l(:thumb).to_s), f.file_field :profile_image);@output_buffer...

Thanks in advanced.

Sonny Black
  • 1,585
  • 4
  • 23
  • 41

1 Answers1

0

So firstly, what do you think this error might me. Most common errors ever:

Sites/Friendiose-master/app/views/home/landing_welcome.html.erb:9: syntax error, unexpected tSYMBEG, expecting ')'
...l(:thumb).to_s), f.file_field :profile_image);@output_buffer...

I'm not going to give you full answer but teach you to think how you can debug it.

https://github.com/carrierwaveuploader/carrierwave

That is the documentation for carrierwave. When showing the image it says the following:

    <%= form_for @user, :html => {:multipart => true} do |f| %>
  <p>
    <label>My Avatar</label>
    <%= image_tag(@user.avatar_url) if @user.avatar? %>
    <%= f.file_field :avatar %>
    <%= f.hidden_field :avatar_cache %>
  </p>
<% end %>

One tip and this is not me being sarcastic but get used to reading alot and googling even more. I haven't used paperclip but I can see the issues from 2 mins googling.

Ruby on Rails using link_to with image_tag

There is how to create a link with an image.

From that link look at the difference between yours:

<%= link_to (image_tag current_user.profile_image_url(:thumb).to_s), edit_account_path(current_user)%>

and the correct way:

<%=link_to( image_tag(participant.user.profile_pic.url(:small)), user_path(participant.user), :class=>"work") %>

What does the error say you are missing?

It is not always great to give people an answer straight away but the keys on how to figure it out.

Community
  • 1
  • 1
Shaun Frost Duke Jackson
  • 1,256
  • 1
  • 10
  • 22