Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Update slug before save a document #380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

class Document < ActiveRecord::Base
belongs_to :category
before_save :update_slug
extend FriendlyId
friendly_id :name, use: :slugged

validates :name, :link, :presence => true
validates :name, :length => { :minimum => 2 }
validates :name, :uniqueness => true
validates :link, :url => true

private

def update_slug
self.slug = name.parameterize
end
end