Inside a loop in my views I have the following code, that combines a few variables for each record:
<% $theurl = newbrandurl + "/?utm_campaign=" + unique_id + "&utm_source=sales" %>
<%= link_to $theurl, class: "btn btn-success" do %>
Order
<% end %>
But that's only in my views. What I want to do is to get this done outside of my views after an Order get's saved to the DB and save the link to the DB. Is that possible?
Edit:
My Model:
class Sale < ActiveRecord::Base
attr_accessible :url
after_create :save_link
def save_link
brandurl = Brand.where(:company => @sale.brand).pluck(:url)
newbrandurl = brandurl.shift.strip
unique_id = [@sale.token, @sale.created_at.strftime('%d%m%y-%H:%M:%SUTC')].join("&")
self.save_link = newbrandurl + "/?utm_campaign=" + unique_id + "&utm_source=sales"
end
end