0

well, i got some issues to get a background image with paperclip, actually i got this

In app/views/layouts/application.html.erb

<head>
  ...
</head>
<body style="<%= show_user_bg %>">
  ...
</body>

In app/helpers/application_helper.rb

module ApplicationHelper
  def show_user_bg
    "background:transparent url(#{@user.background_image}) no-repeat fixed left top;"
  end
end

and this module helper

module ApplicationHelper
  def show_user_bg
    # Show user background
    if user_signed_in?
      "background:transparent url(#{@user.background_image}) no-repeat fixed left top;"
    # Otherwise, show a default background image
    else
      "background:transparent url('/images/default_bg.png') no-repeat fixed left top;"
    end
  end
end

but, when i try to get access to the image i dont know where to get it.

resume, i want to get this

<%= image_tag(@user.background.url, :width => "100%") %>

to this

<div style="background:transparent url(#{@user.background.url}) no-repeat fixed left top;">

any help would be appreciated <3 thx!

Siguza
  • 21,155
  • 6
  • 52
  • 89

1 Answers1

0

You have to wrap the url in quotes url('#{@user.background_image}') but I would like to see your User class. You are mixing @user.background_image with @user.background.url - the latter looks like the one you should use. But use the debugger and see for yourself.

Also, if you have added styles to your paperclip attachment, you might want to referenda that when you call the url. (Like :thumb or :large or what have you...)

Thomas
  • 622
  • 5
  • 13
  • the .url is the paperclip synthax, and the image isn't the problem, i can add any image from my assets, the paperclip is the issue, i mean, the path (that's the url, or at least that was that i thought) – Felipe Eduardo Rojas Apr 07 '15 at 23:43
  • anyways, i fixed that using bootstrap, i gave it some properties to make it act like a background – Felipe Eduardo Rojas Apr 07 '15 at 23:45