ruby on rails - Define variable in model method -
i'm getting keywords
array html form different keywords. need put them string value keyword1,keyword2,keyword3
.
the problem keywords_line
string. see has value inside of .each cycle has not out of it. how set keywords_line
work correctly?
# models/item.rb before_save :create_slug_and_keywords def create_slug_and_keywords if defined? self.keywords self.keywords.each |k| if defined? keywords_line keywords_line = keywords_line + ',' + k else keywords_line = k end end if defined? keywords_line # keywords_line not defined here keywords = keywords_line else keywords = nil end end
if keywords array, self.keywords.join(',')
and link doc.
Comments
Post a Comment