I have an app where users can send a unique link (a postcard to invite other people) to others via email, sms and whatsapp through clicking on a button.
The app features a button in the cards show method that says "Send card to a friend via email" and when people click on it, their email app opens and they can send the link:
<a href="mailto:?subject=Postcard for you!&body=You received a nice postcard! Check it out here: <%= u @sending_url %>">
<button class="btn btn-large btn-default">Send card to a friend via email</button>
</a>
The link/URL @sending_url is created by a helper method and is composed by the URL and two parameters: the inviter_id (which is the current user's id) and a token (@token) generated through SecureRandom.uuid. A link which my app generates looks like this:
https://chaos-jadz.c9users.io/cards/3?inviter_id=1&token=b39f0488-de54-431e-a261-4da2feae6012
What I want to do now is: once a user clicks on this button the app should not only open the email app but also store the token in the database. Therefore I have:
token.rb
class Token < ActiveRecord::Base
end
schema.rb
create_table "tokens", force: :cascade do |t|
t.string "token"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
My question now is: How can I implement a button in my show.html.erb of the card that once clicked saves the token (generated in my card show method) in the database and at the same time opens the users email app?