diff options
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/application_controller.rb | 10 | ||||
| -rw-r--r-- | app/controllers/blogs_controller.rb | 7 | ||||
| -rw-r--r-- | app/controllers/comments_controller.rb | 9 | ||||
| -rw-r--r-- | app/controllers/quotes_controller.rb | 14 | ||||
| -rw-r--r-- | app/controllers/streams_controller.rb | 19 |
5 files changed, 55 insertions, 4 deletions
| diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0174cae..ad46fb9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb | |||
| @@ -1,9 +1,19 @@ | |||
| 1 | class ApplicationController < ActionController::Base | 1 | class ApplicationController < ActionController::Base |
| 2 | protect_from_forgery with: :exception | 2 | protect_from_forgery with: :exception |
| 3 | before_action :choose_random_song | ||
| 3 | 4 | ||
| 4 | private | 5 | private |
| 5 | 6 | ||
| 6 | def after_sign_out_path_for(resource) | 7 | def after_sign_out_path_for(resource) |
| 7 | new_session_path(resource) | 8 | new_session_path(resource) |
| 8 | end | 9 | end |
| 10 | |||
| 11 | def choose_random_song | ||
| 12 | ids = Scrobble.ids | ||
| 13 | if ids.empty? | ||
| 14 | @random_song = nil | ||
| 15 | else | ||
| 16 | @random_song = Scrobble.find(ids.sample) | ||
| 17 | end | ||
| 18 | end | ||
| 9 | end | 19 | end |
| diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 033d6bb..6e80754 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | require 'redcarpet/render_strip' | 1 | |
| 2 | 2 | ||
| 3 | class BlogsController < ApplicationController | 3 | class BlogsController < ApplicationController |
| 4 | include ApplicationHelper | ||
| 4 | 5 | ||
| 5 | def summary | 6 | def summary |
| 6 | @blogs = Blog.where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) | 7 | @blogs = Blog.where(published: true).order(published_at: :desc).paginate(page: params[:page], per_page: 10) |
| @@ -27,12 +28,12 @@ class BlogsController < ApplicationController | |||
| 27 | @prev = @blog.prev | 28 | @prev = @blog.prev |
| 28 | @next = @blog.next | 29 | @next = @blog.next |
| 29 | 30 | ||
| 30 | body = Redcarpet::Markdown.new(Redcarpet::Render::StripDown).render(@blog.body) | 31 | body = stripped_markdown(@blog.body) |
| 31 | 32 | ||
| 32 | set_meta_tags(og: { | 33 | set_meta_tags(og: { |
| 33 | title: @blog.title, | 34 | title: @blog.title, |
| 34 | type: "article", | 35 | type: "article", |
| 35 | description: (body.length <= 300 ? body : body[0..299]), | 36 | description: body[0, 299], |
| 36 | url: blog_url(@blog, host: "www.fourisland.com"), | 37 | url: blog_url(@blog, host: "www.fourisland.com"), |
| 37 | article: { | 38 | article: { |
| 38 | published_time: @blog.published_at.iso8601, | 39 | published_time: @blog.published_at.iso8601, |
| diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index b305d0a..31fe411 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb | |||
| @@ -5,6 +5,12 @@ class CommentsController < ApplicationController | |||
| 5 | raise ActiveRecord::RecordNotFound unless @blog | 5 | raise ActiveRecord::RecordNotFound unless @blog |
| 6 | raise ActiveRecord::RecordNotFound unless @blog.published | 6 | raise ActiveRecord::RecordNotFound unless @blog.published |
| 7 | 7 | ||
| 8 | unless verify_recaptcha | ||
| 9 | flash.alert = "Error posting comment." | ||
| 10 | render "blogs/show" | ||
| 11 | return | ||
| 12 | end | ||
| 13 | |||
| 8 | @comment = @blog.comments.new(comment_params) | 14 | @comment = @blog.comments.new(comment_params) |
| 9 | @comment.request_ip = request.ip | 15 | @comment.request_ip = request.ip |
| 10 | @comment.user_agent = request.user_agent | 16 | @comment.user_agent = request.user_agent |
| @@ -56,7 +62,8 @@ class CommentsController < ApplicationController | |||
| 56 | CommentMailer.with(comment: @comment).reply_comment_email.deliver_later | 62 | CommentMailer.with(comment: @comment).reply_comment_email.deliver_later |
| 57 | end | 63 | end |
| 58 | else | 64 | else |
| 59 | CommentMailer.with(comment: @comment).new_pending_comment_email.deliver_later | 65 | # CommentMailer.with(comment: @comment).new_pending_comment_email.deliver_later |
| 66 | # I'm disabling pending comment emails, at least for now, because I am getting too many. | ||
| 60 | end | 67 | end |
| 61 | else | 68 | else |
| 62 | flash.alert = "Error posting comment." | 69 | flash.alert = "Error posting comment." |
| diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb index d4800cb..468f6ea 100644 --- a/app/controllers/quotes_controller.rb +++ b/app/controllers/quotes_controller.rb | |||
| @@ -30,6 +30,20 @@ class QuotesController < ApplicationController | |||
| 30 | end | 30 | end |
| 31 | end | 31 | end |
| 32 | 32 | ||
| 33 | def search_form | ||
| 34 | @q = Quote.published.ransack | ||
| 35 | end | ||
| 36 | |||
| 37 | def search | ||
| 38 | @quotes = Quote.published.ransack(params[:q]).result(distinct: true).paginate(page: params[:page], per_page: 10) | ||
| 39 | |||
| 40 | respond_to do |format| | ||
| 41 | format.html { render :list } | ||
| 42 | format.json { render :json => @quotes } | ||
| 43 | format.xml { render :xml => @quotes } | ||
| 44 | end | ||
| 45 | end | ||
| 46 | |||
| 33 | def random | 47 | def random |
| 34 | picked = Quote.where(state: :published).ids.sample | 48 | picked = Quote.where(state: :published).ids.sample |
| 35 | redirect_to quote_url(picked) | 49 | redirect_to quote_url(picked) |
| diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb index 664f533..ec4cee8 100644 --- a/app/controllers/streams_controller.rb +++ b/app/controllers/streams_controller.rb | |||
| @@ -1,7 +1,26 @@ | |||
| 1 | class StreamsController < ApplicationController | 1 | class StreamsController < ApplicationController |
| 2 | include ApplicationHelper | ||
| 3 | |||
| 4 | def index | ||
| 5 | @streams = Stream.order(latest_post_at: :desc).paginate(page: params[:page], per_page: 10) | ||
| 6 | end | ||
| 2 | 7 | ||
| 3 | def show | 8 | def show |
| 4 | @stream = Stream.find_by_slug(params[:slug]) | 9 | @stream = Stream.find_by_slug(params[:slug]) |
| 10 | @updates = @stream.updates.paginate(page: params[:page], per_page: 10) | ||
| 11 | |||
| 12 | body = stripped_markdown(@stream.body) | ||
| 13 | |||
| 14 | set_meta_tags(og: { | ||
| 15 | title: @stream.title, | ||
| 16 | type: "article", | ||
| 17 | description: body[0, 299], | ||
| 18 | url: stream_url(@stream, host: "www.fourisland.com"), | ||
| 19 | article: { | ||
| 20 | published_time: @stream.created_at.iso8601, | ||
| 21 | modified_time: @stream.latest_post_at.iso8601 | ||
| 22 | } | ||
| 23 | }) | ||
| 5 | end | 24 | end |
| 6 | 25 | ||
| 7 | end | 26 | end |
