Record Not Found rails 5 ActiveRecord Error
<p>I am trying to use a vanity URL that uses the SecureRandom issued ident to a culvert, and then display that culvert via the show page. </p>

<p>This is a screenshot of the error message:
<a href="https://i.stack.imgur.com/qB0YE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qB0YE.jpg" alt="enter image description here"></a></p>

<p>This is a screenshot of the browser url:
<a href="https://i.stack.imgur.com/EJpBD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EJpBD.png" alt="enter image description here"></a></p>

<blockquote>
  <p><strong>My Culvert Controller is:</strong></p>
</blockquote>

<p>I have tried Both: </p>

<pre><code>@culvert = Culvert.find_by_culvert_ident(params[:id])
  AND
@culvert = Culvert.find_by_id(params[:culvert_ident])
</code></pre>

<p>In my culvert controller show action, both yield the same result (screenshot)</p>

<pre><code>  private
    # Use callbacks to share common setup or constraints between actions.
    def set_culvert
      @culvert = Culvert.find_by_culvert_ident(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def culvert_params
      params.require(:culvert).permit(:culvert_ident, :latitude, :longitude, :address, :user_id)
    end
</code></pre>

<p>This is my Culvert Model ident generator and vanity url methods:</p>

<pre><code>  before_create :generate_culvert_ident

  # Relationships
  belongs_to :user

  # Model Validations
  validates_uniqueness_of :culvert_ident

  # Ident Generator
  def generate_culvert_ident
    begin
      self.culvert_ident = SecureRandom.hex(3).upcase
      other_culvert = Culvert.find_by(culvert_ident: self.culvert_ident)
    end while other_culvert
  end

  # Url Direction
  def to_param
    culvert_ident
  end
</code></pre>

<p>So my goal is to create the culvert, auto assign a unique identifier, save it and display the culvert using the custom identifier as opposed to the standard 1,2,3,4 id's</p>

<p>this works in another web app i have used, is setup exactly the same but i am getting this error here and cant figure out why. Please let me knwo if you require further info!</p>

<p>**</p>

<blockquote>
  <p>EDIT # 1 - Adds Screenshot of Console output</p>
</blockquote>

<p>**</p>

<p><a href="https://i.stack.imgur.com/oQwFa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oQwFa.png" alt="enter image description here"></a>
<a href="https://i.stack.imgur.com/VDYgn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VDYgn.png" alt="enter image description here"></a></p>