Class: Blog::BlogpostController
- Inherits:
-
MainController
- Object
- MainController
- Blog::BlogpostController
- Defined in:
- lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb
Constant Summary collapse
- LATEST_FOR_PREVIEW =
2
- BLOGPOSTS_FOR_PREVIEW =
6
- RELATED_FOR_PREVIEW =
3
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb', line 6 def index # Fetch data as Json data = BlogpostParser.fetch_all_published categories = CategoryParser.fetch_all_categories # Build Blogposts by category @categories_with_blogposts = categories.map do |category| Blog::Category.new(category).build_n_blogposts_by_category(data, BLOGPOSTS_FOR_PREVIEW) end # Build latest Blogposts @latest_blogposts = data.first(LATEST_FOR_PREVIEW) .map { |attributes| Blog::Blogpost.new(attributes) } end |
#show ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nexmo_developer/app/controllers/blog/blogpost_controller.rb', line 22 def show @blogpost = Blog::Blogpost.build_blogpost_from_path(params[:blog_path], 'en') @blog_button_path = "https://ui.idp.vonage.com/ui/auth/registration?icid=tryitfree_adpblog-#{params[:blog_path]}_nexmodashbdfreetrialsignup_banner" redirect_to blog_path unless @blogpost.published data = BlogpostParser.fetch_all_published @related_blogposts = data.select { |b| b['category']['slug'] == @blogpost.category.slug && b['title'] != @blogpost.title } .first(RELATED_FOR_PREVIEW) .sort_by { |b| b['updated_at'] }.reverse .map { |attributes| Blog::Blogpost.new attributes } end |