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| %>
My Avatar URL: <%= image_tag(@user.avatar_url) if
@user.avatar? %> <%= f.text_field :remote_avatar_url %>
%>
It means that the parameter avatar should have the ‘_url’ sufix.
You can make a before_filter to change that, or a Service Object that
would
properly save the User with the correct parameter.
===================
Alexandre Mondaini Calvão
“Nossa recompensa se encontra no esforço e não no resultado. Um esforço
total é uma vitória completa.” [Ghandi]
2014-10-03 0:10 GMT-03:00 Adham El-Deeb [email protected]:
It also requires the ‘remote’ prefix.
===================
Alexandre Mondaini Calvão
“Nossa recompensa se encontra no esforço e não no resultado. Um esforço
total é uma vitória completa.” [Ghandi]
2014-10-03 12:19 GMT-03:00 Alexandre Calvão [email protected]:
there is no html on my app it is an API and i want to save the user
from the *User Model *it self
On Fri, Oct 3, 2014 at 8:54 AM, Adham El-Deeb [email protected]
wrote:
there is no html on my app it is an API and i want to save the user from the
User Model it self
- What client are you using?
- What params are being logged for a create request?
- 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…
–
Hassan S. ------------------------ [email protected]
twitter: @hassan
Thanks! *Alexandre *it works
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
===================
Alexandre Mondaini Calvão
“Nossa recompensa se encontra no esforço e não no resultado. Um esforço
total é uma vitória completa.” [Ghandi]
2014-10-03 14:04 GMT-03:00 Hassan S.
[email protected]: