Merge pull request #76 from wikyd/custom_urls
Allow users to set a custom url for a blog post independent of the title
This commit is contained in:
commit
6c14d65673
4 changed files with 27 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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} %>
|
||||
|
|
|
@ -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:
|
||||
|
|
9
db/migrate/5_add_custom_url_field_to_blog_posts.rb
Normal file
9
db/migrate/5_add_custom_url_field_to_blog_posts.rb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue