Repository URL to install this package:
Version:
2.0.0 ▾
|
app |
config |
db |
lib |
README.md |
Rakefile |
This is the basic News/Blog Rails Engine by Neoteric Design, Inc.
## Gemfile gem 'articular', '~> 1.7.0'
$ bundle install
$ rails g articular:install
-or-
$ rails g articular:install MODEL_NAME (default is NewsPost)
$ rake db:migrate db:test:prepare
Out of the box, you get a NewsPost model and a NewsPostsController configured to use "articular"
class NewsPost < Articular::Article # Any model can do this, and doesn't need a table created for it end class NewsPostsController < ApplicationController articular # Any controller can do this end
@article = NewsPost.find('slug or id') @article.title #=> 'The post title string field' @article.excerpt #=> 'The post excerpt text field' @article.body #=> 'The post body text field' @article.published_at #=> Wed May 1, 2013 (date field) @article.meta_description #=> For using in the META tag for page description @article.next #=> The next published article, chronologically @article.prev #=> The previous published article, chronologically NewsPost.published #=> All non-drafted posts with published_at <= Date.today NewsPost.drafted #=> All drafted posts NewsPost.future #=> All non-drafted posts with published_at >= Date.today NewsPost.by_month(year, month) #=> All posts in the given month NewsPost.by_year(year) #=> All posts in the given year # be careful not to use these without scoping them to .published posts in public view templates!
Add something similar to your model:
acts_as_taggable_on :topics attr_accessible :topic_list
Articular view helpers are to help with article_path
and article_url
to avoid having to pass in the year, month, and post id to the standard rails url helper methods
article_path(article) #=> same thing as news_post_path(article.published_at.year, article.published_at.month, article) article_url(article) #=> same thing as news_post_url(article.published_at.year, article.published_at.month, article)
This works regardless of the class of the given article.
@some_post = SomeOtherArticularSubClass.find('slug')
article_path(@some_post) #=> same thing as some_other_articular_subclass_path(...)
article_url(@some_post) #=> same thing as some_other_articular_subclass_url(...)
class AnyNameController < ApplicationController articular # any controller can do this end # provides 4 actions # article_class is discovered based on controller_name def index @title = index_title @articles = article_class.published.paginate(pagination_options) respond_with(@articles) end def show @article = article_class.published.find(params[:id]) @title = show_title end def tagged @title = tagged_title @articles = article_class.published .tagged_with(params[:tag_name]) .paginate(pagination_options) render :template => "#{plural_model_name}/index" end def archive @title = archive_title set_archive_collection(params[:year], params[:month]) render :template => "#{plural_model_name}/index" end # controller helper methods base_title
class SomeController < ApplicationController articular private def index_title 'Customize your title here' end end ## The current default titles def tagged_title "#{base_title} posted under '#{params[:tag_name]}'" end def archive_title "#{base_title} posted in #{month_name} #{params[:year]}" end def index_title base_title end def show_title @article.title end def base_title "Articles" end
# in your controller # (showing defaults) def pagination_options { :per_page => 10, :page => params[:page] } end
Include Javascript
//= require articular
Include CSS
@import "articular";
Permit Parameters: :body, :excerpt, :published_at, :title, :meta_description