title: Generating a unique URL with tokens in Rails 4 for an external form response
body: <p>I have a 'Feedback' model whereby a user should be able to request feedback on his/her job performance. I have written basic actions for creating a new feedback request, and the mailer for sending the request to the provider (person who will respond with feedback).</p>
  
  <p><strong>I would like advice from the community on implementing the following:</strong></p>
  
  <ul>
  <li>Once a new feedback request is created, the email that is sent should contain a link to a form where the provider can input his feedback on the users performance.</li>
  <li>The feedback provider should not be required to log-in or sign-up in any way (i.e. completely external to the application).</li>
  <li>Once submitted, feedback from the provider should be captured in the
  system.</li>
  </ul>
  
  <p><strong>Now, I have the following ideas to implement it, but am not sure if this is the best way to proceed:</strong></p>
  
  <ul>
  <li>Generate a unique token upon the creation of a new feedback request. Something like this: <a href="https://stackoverflow.com/questions/6021372/best-way-to-create-unique-token-in-rails">Best way to create unique token in Rails?</a>.</li>
  <li>The token should then be entered into 'feedbacks' table.</li>
  <li>Mailer should then generate variable (e.g. @url) which generates link to another controller (let's say 'external_feedback' and action which does not require log-in (e.g. no before_filter :authenticate_user! from Devise). </li>
  <li>That URL should contain a parameter with the token for the specific feedback request. </li>
  <li>The action should be to update the 'feedback' request and a form generated with simple_form.</li>
  </ul>
  
  <p>The whole thing is similar to responding to a questionnaire or survey (like Survey Monkey).</p>
  
  <p>After some research I believe the Friendly ID gem may be useful here. I was also reading Section 8 of <a href="http://guides.rubyonrails.org/form_helpers.html" rel="noreferrer">http://guides.rubyonrails.org/form_helpers.html</a> and perhaps I need to implement an authenticity_token in the formal sense. What I am really looking for is:</p>
  
  <ul>
  <li>Is the above approach the generally correct way to go about doing this?</li>
  <li>If so, any specifics on how you would implement it (with or without Friendly ID)?</li>
  <li>Do you know of any gems that exist for generating such URLs/tokens?</li>
  </ul>
  
  <p>Thank you in advance. I am now including the current state of model and controller details:</p>
  
  <pre><code>feedback.rb
  # == Schema Information
  #
  # Table name: feedbacks
  #
  #  id           :integer          not null, primary key
  #  user_id      :integer
  #  p_first_name :string(255)
  #  p_last_name  :string(255)
  #  p_email      :string(255)
  #  goal_id      :integer
  #  u_comment    :text
  #  p_comment    :text
  #  created_at   :datetime
  #  updated_at   :datetime
  #
  
  class Feedback &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :goal
  
    has_many :feedback_attributes
  
    validates_presence_of :p_first_name, :p_last_name, :p_email, :goal_id
  
  end
  </code></pre>
  
  <p>And this is my mailer:</p>
  
  <pre><code>class FeedbackMailer &lt; ActionMailer::Base
  
     def feedback_request(user, feedback)
      @user = user
      @feedback = feedback
      @url  = 'http://thisistheexampleurlforfeedback'
      mail(to: @feedback.p_email, subject: "#{@user.first_name} #{@user.last_name} has requested your feedback", from: @user.email)
    end
  
  end
  </code></pre>