Carrierwave save nil value on database

I’m using Rails-api with mongoid. I try to upload user avatar using Carrierwave from a remote url.

I got theremote url form omniauth-facebook image params.

The problem is the avatar field in Databass have nil value after save.

This is my app on github https://github.com/adham90/pp

From the carrierwave documentation

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

It also requires the ‘remote’ prefix.

there is no html on my app it is an API and i want to save the user from the User Model it self

1) What client are you using? 2) What params are being logged for a create request? 3) What does the log show for a request sequence?

I have no experience with Carrierwave but are you sure that it's not expecting a "remote_avatar_url" param by default, as Alexandre suggested? That has nothing to do with whether you're using HTML or not...

Adham,

The code I posted was just to show you that Carrierwave requires that you add a suffix “remote_” and a prefix ‘_url’ to the parameter managed by carrierwave, in order for it to work with urls.

In your case the following code is not doing that, you are passing the the parameter ‘avatar’ without the sufix and the prefix.

user_controller.rb

28- @user = User.new(user_params)

def user_params params.require(:user).permit(:username, :name, :email, :password, :password_confirmation, :age, :gender, :avatar) end

You gotta find a way to pass ‘remote_avatar_url’ => ‘http:://www.test.com/someimage.jpg

That is what carrierwave requires to work with url instead of files.

`s

Thanks! **Alexandre **it works :smiley: