0

I'm trying to insert the URL of the page into uploaded image.
I already have the code like this below but it doesn't work.

Is there something wrong in my model? How can I fix this?

My associations

  • User has_one :profile
  • Profile belongs_to :user

models/user.rb

before_save :text_to_insert? 

def text_to_insert
    nickname = self.profile.nickname 
end

has_attached_file :user_avatar,
    :styles => {
    :thumb=> "100x100>",
    :small  => "400x400>" }, 
     :convert_options => {
     :small => '-fill white  -undercolor "#00000080"  -gravity South -annotate +0+5 " example.com/'+ nickname +' "' } 
rayryeng
  • 102,964
  • 22
  • 184
  • 193
Foo
  • 800
  • 1
  • 7
  • 17
  • I'm not entirely sure but I think you want to look at interpolation. See http://stackoverflow.com/questions/11058271/print-out-the-zombies-name-and-graveyard-rails-for-zombies/11058367#11058367 – DaMainBoss Jan 03 '13 at 16:52
  • In addition, if you don't know how to get the URL of the current page, have a look at this http://stackoverflow.com/questions/2165665/how-do-i-get-the-current-url-in-ruby-on-rails – DaMainBoss Jan 03 '13 at 17:04
  • I know how to access to columns from controller or view but model:( – Foo Jan 03 '13 at 17:30

1 Answers1

1

before saving , you are using text_to_insert? method which doesn't exist thatwhy it is returning false,so it fails to save . It looks like typos ,try removing ? after :text_to_insert ie

before_save :text_to_insert

Please be sure that is valid self.profile.nickname

Paritosh Piplewar
  • 7,982
  • 5
  • 26
  • 41
  • It still says this error **syntax error, unexpected tUPLUS, expecting keyword_do or '{' or '('** Is the way of coding wrong with :convert_options? – Foo Jan 03 '13 at 17:43
  • if I code self.profile.nickname, here self means current accessing record of **User** right? – Foo Jan 03 '13 at 17:48
  • try checking `has_attached_file` and check whether it accepts `options={}` or not . generally this is `p = { :n => 'd' }` valid code and `:n => {:s => 'bar'}` is invalid – Paritosh Piplewar Jan 03 '13 at 18:02