Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Object.from_param #22

Closed
wants to merge 1 commit into from
Closed

Conversation

andruby
Copy link

@andruby andruby commented May 12, 2011

A small patch to allow models to define a from_param method that can be used for slug/permalink urls.
Define both to_param and a self.from_param(id) methods in your model and get nice url's for free!

example model:

class Person
  include Mongoid::Document
  field :name
  validates_uniqueness_of :name

  def to_param
    name
  end

  def self.from_param(param)
    self.where(name: param).first
  end
end

@mrmemes-eth
Copy link
Contributor

Thanks for the pull request. This seems fairly application specific though, so I won't pull it into master. As of right now this is probably something I would personally use, but I would opt for overriding the default_exposure instead.

Thanks again!

hashrocketeer pushed a commit that referenced this pull request Oct 8, 2015
Document Adequate Exposure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants