lundi 5 octobre 2015

include and If statement inside a for each

This is driving me nuts as it seems so simple.

clients can upload up to three files

I want to set the status of the file based on the description they choose.

the upload works fine and a static status is fine - but a dynamic one errors out.

 def build_document_objects
[:first, :second, :third].each do |doc|

  d = "#{doc}_document"
  if self.send("#{d}_type") == "this Type"
  doc_status = 'one'
else
  doc_status = 'two'

  self.send("#{d}=", user.documents.new(

    description: "Foo",
    file: self.send("#{d}_file"),
    document_type: self.send("#{d}_type"),

  status: doc_status

    ))
  end
end
end

Aucun commentaire:

Enregistrer un commentaire