diff options
author | Joe Sak <joe@joesak.com> | 2011-06-17 07:45:16 -0700 |
---|---|---|
committer | Joe Sak <joe@joesak.com> | 2011-06-17 07:45:16 -0700 |
commit | 6c14d65673fd3615980f817189f77c16f04eff07 (patch) | |
tree | c636f7d56e9c9d03c987d0a54a77af8238383739 /app | |
parent | b3c06562a4a58e2cd0711f126f58d09b22c97e74 (diff) | |
parent | e1390a0d72e2dc35f1306d11e1e756c138903572 (diff) | |
download | refinerycms-blog-6c14d65673fd3615980f817189f77c16f04eff07.tar.gz refinerycms-blog-6c14d65673fd3615980f817189f77c16f04eff07.tar.bz2 refinerycms-blog-6c14d65673fd3615980f817189f77c16f04eff07.zip |
Merge pull request #76 from wikyd/custom_urls
Allow users to set a custom url for a blog post independent of the title
Diffstat (limited to 'app')
-rw-r--r-- | app/models/blog_post.rb | 8 | ||||
-rw-r--r-- | app/views/admin/blog/posts/_form.html.erb | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb index 5c0101d..a010d98 100644 --- a/app/models/blog_post.rb +++ b/app/models/blog_post.rb @@ -21,12 +21,12 @@ class BlogPost < ActiveRecord::Base validates :title, :presence => true, :uniqueness => true validates :body, :presence => true - has_friendly_id :title, :use_slug => true, + has_friendly_id :friendly_id_source, :use_slug => true, :default_locale => (::Refinery::I18n.default_frontend_locale rescue :en), :approximate_ascii => RefinerySetting.find_or_set(:approximate_ascii, false, :scoping => 'blog'), :strip_non_ascii => RefinerySetting.find_or_set(:strip_non_ascii, false, :scoping => 'blog') - attr_accessible :title, :body, :tag_list, :draft, :published_at, :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids + attr_accessible :title, :body, :tag_list, :draft, :published_at, :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids, :custom_url scope :by_archive, lambda { |archive_date| where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]) @@ -61,6 +61,10 @@ class BlogPost < ActiveRecord::Base }.compact end + def friendly_id_source + custom_url.present? ? custom_url : title + end + class << self def next current_record self.send(:with_exclusive_scope) do diff --git a/app/views/admin/blog/posts/_form.html.erb b/app/views/admin/blog/posts/_form.html.erb index c0467fd..abff4f2 100644 --- a/app/views/admin/blog/posts/_form.html.erb +++ b/app/views/admin/blog/posts/_form.html.erb @@ -73,6 +73,15 @@ </ul> <h3><%= t('.published_at') %></h3> <%= f.datetime_select :published_at %> + + <div class='field'> + <span class='label_with_help'> + <%= f.label :custom_url, t('.custom_url') %> + <%= refinery_help_tag t('.custom_url_help') %> + </span> + <%= f.text_field :custom_url, :class => "widest" %> + </div> + </div> <div class='hemisquare right_side'> <%= render :partial => '/seo_meta/form', :locals => {:form => f} %> |