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 | |
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
-rw-r--r-- | app/models/blog_post.rb | 8 | ||||
-rw-r--r-- | app/views/admin/blog/posts/_form.html.erb | 9 | ||||
-rw-r--r-- | config/locales/en.yml | 4 | ||||
-rw-r--r-- | db/migrate/5_add_custom_url_field_to_blog_posts.rb | 9 |
4 files changed, 27 insertions, 3 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} %> diff --git a/config/locales/en.yml b/config/locales/en.yml index eb886a9..a4ad0fd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -38,6 +38,8 @@ en: toggle_advanced_options: Click to access meta tag settings and menu options save_as_draft: Save as Draft published_at: Publish Date + custom_url: Custom Url + custom_url_help: Generate the url for the blog post from this text instead of the title. index: no_items_yet: 'There are no Blog Posts yet. Click "%{create}" to add your first blog post.' uncategorized: @@ -150,4 +152,4 @@ en: message: Message blog_post: title: Title - body: Body
\ No newline at end of file + body: Body diff --git a/db/migrate/5_add_custom_url_field_to_blog_posts.rb b/db/migrate/5_add_custom_url_field_to_blog_posts.rb new file mode 100644 index 0000000..5a8901e --- /dev/null +++ b/db/migrate/5_add_custom_url_field_to_blog_posts.rb @@ -0,0 +1,9 @@ +class AddCustomUrlFieldToBlogPosts < ActiveRecord::Migration + def self.up + add_column :blog_posts, :custom_url, :string + end + + def self.down + remove_column :blog_posts, :custom_url + end +end |