Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>FriendlyID includes a Reserved module which prevents a list of provided words from being used as friendly slugs. You could add your static routes to the reserved words array which would prevent someone from overwriting your routes.</p> <p>From the FriendlyId RDocs</p> <pre><code>FriendlyId.defaults do |config| config.use :reserved # Reserve words for English and Spanish URLs config.reserved_words = %w(new edit nueva nuevo editar) end </code></pre> <p>If you still want to allow for a title that is reserved you can make a new method that FriendlyId would use for the slug. This piece from the RDocs explains that </p> <hr> <p><strong>Column or Method?</strong></p> <p>FriendlyId always uses a method as the basis of the slug text - not a column. It first glance, this may sound confusing, but remember that Active Record provides methods for each column in a model's associated table, and that's what FriendlyId uses.</p> <p>Here's an example of a class that uses a custom method to generate the slug:</p> <pre><code>class Person &lt; ActiveRecord::Base friendly_id :name_and_location def name_and_location "#{name} from #{location}" end end bob = Person.create! :name =&gt; "Bob Smith", :location =&gt; "New York City" bob.friendly_id #=&gt; "bob-smith-from-new-york-city" </code></pre> <hr> <p>You could create a method like <code>:title_with_id</code> or <code>:title_with_rand</code>. it's up to you and how you'd like the slugs to look.</p> <p>You would also want to make sure your <code>routes.rb</code> has your static routes listed prior to the routes for with the friendly id. The first route dispatcher matches is where the request will be processed.</p>
 

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