Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can have a boolean on your masterpiece model called public. If the picture is public then it can be accessible to anyone. However, if it is not public, then using your return URL will not do anything.</p> <p>Your public url can be created through a hash. I typically like having the hash token created when the model is created.</p> <p><code>rails g migration add_hash_token_to_masterpieces hash_token</code></p> <p>In your model, you can use the <code>before_create</code> method to call a private method taht will update your hash_token with a randomized hex.</p> <pre><code> before_create :generate_hash_token private def generate_hash_token begin self.hash_token = SecureRandom.hex end while self.class.exists?(hash_token: hash_token) end </code></pre> <p>Then in your routes file, you can do something like this</p> <p><code>match "/public/:hash_token" =&gt; "masterpieces#public_masterpiece", as: "public"</code></p> <p>Then in your controller you can have a find method of your hash token and have a corresponding view to display the image for the public user. Notice <code>_and_public</code> is only finding the ones that are public. Even if the hash is valid, it will not return the record if the masterpiece is not public.</p> <pre><code>def public_masterpiece @masterpiece = Masterpiece.find_by_hash_token_and_public(params[:hash_token], true) ... end </code></pre> <p>Then in your masterpiece views, you can have a file called <code>public_masterpiece.html.erb</code> which is a specific render for users who do not yet have an authorized account, but still can view the picture. If you are using a gem like cancan for authorization, you will want to make sure that you allow public_masterpiece action.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload