From 5dddde5dee7beecfb6824b208c4fb86c781a27f9 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 21 Oct 2023 00:55:24 -0400 Subject: Added quote submission (and random) --- app/assets/stylesheets/quotes.css.scss | 2 ++ app/controllers/quotes_controller.rb | 28 ++++++++++++++++++++++++++++ app/views/layouts/quotes.html.haml | 3 +++ app/views/quotes/new.html.erb | 2 -- app/views/quotes/new.html.haml | 24 ++++++++++++++++++++++++ config/routes.rb | 1 + 6 files changed, 58 insertions(+), 2 deletions(-) delete mode 100644 app/views/quotes/new.html.erb create mode 100644 app/views/quotes/new.html.haml diff --git a/app/assets/stylesheets/quotes.css.scss b/app/assets/stylesheets/quotes.css.scss index 8cf4eae..c1b1178 100644 --- a/app/assets/stylesheets/quotes.css.scss +++ b/app/assets/stylesheets/quotes.css.scss @@ -1,4 +1,6 @@ /* *= require normalize-rails + *= require tags-input + *= require jquery-ui *= require_tree ./quotes */ diff --git a/app/controllers/quotes_controller.rb b/app/controllers/quotes_controller.rb index fb5e33c..58af7bb 100644 --- a/app/controllers/quotes_controller.rb +++ b/app/controllers/quotes_controller.rb @@ -26,6 +26,11 @@ class QuotesController < ApplicationController end end + def random + picked = Quote.ids.sample + redirect_to quote_url(picked) + end + def tags @tags = Quote.published.tag_counts_on(:tags) end @@ -51,6 +56,23 @@ class QuotesController < ApplicationController end def new + @quote = Quote.new + end + + def create + @quote = Quote.new(quote_params) + @quote.submitter = nil if @quote.submitter.empty? + + if user_signed_in? + @quote.state = :published + @quote.save! + + flash[:notice] = "Thank you for submitting your quote!" + redirect_to @quote + else + flash[:error] = "There was an error." + render :new + end end def upvote @@ -94,4 +116,10 @@ class QuotesController < ApplicationController end end end + + private + + def quote_params + params.require(:quote).permit(:content, :notes, :submitter, :tag_list) + end end diff --git a/app/views/layouts/quotes.html.haml b/app/views/layouts/quotes.html.haml index 6d89d91..5555248 100644 --- a/app/views/layouts/quotes.html.haml +++ b/app/views/layouts/quotes.html.haml @@ -18,6 +18,9 @@ %li= link_to_unless_current "Home", quotes_url %li= link_to_unless_current "Latest", latest_quotes_url %li= link_to_unless_current "Top", top_quotes_url + %li= link_to "Random", random_quotes_url + - if user_signed_in? + %li= link_to_unless_current "Submit", new_quote_url %li= link_to_unless_current "Tags", tags_quotes_url %li= link_to_unless_current "Feed", latest_quotes_url(:atom) .cleardiv diff --git a/app/views/quotes/new.html.erb b/app/views/quotes/new.html.erb deleted file mode 100644 index a4c6a0a..0000000 --- a/app/views/quotes/new.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Quotes#new

-

Find me in app/views/quotes/new.html.erb

diff --git a/app/views/quotes/new.html.haml b/app/views/quotes/new.html.haml new file mode 100644 index 0000000..887ff2c --- /dev/null +++ b/app/views/quotes/new.html.haml @@ -0,0 +1,24 @@ +%p.normal You're about to submit a quote to the Four Island Quotes DB! This is great, but first, there are a few rules/guidelines/things you should know before submitting: +%ul + %li Quotes should come from a chat involving one or more Four Island regulars. This is not a strict guideline, as quotes are often submitted from video chats or real life situations possibly involving only one Four Island regular, but just make sure before submitting that the quote you're submitting would be appreciated by other Four Island regulars. + %li Make sure to remove timestamps, if present in your quote, before submitting. + %li If your quote is extremely offensive, it will probably not be approved. This is not referring to profanity--you can leave profanity uncensored in your quotes. + %li If you want to, you can enter your username in the box below the quote labelled "Your username" (this is completely optional). This is mostly for record-keeping and statistical purposes; submitting a quote of yourself being awesome and then signing your name under it won't decrease the chances of it being accepted. + %li You can enter any notes about the quote that may be important (such as context, or if it's a memorable quote, why it's memorable) in the box below your quote. + %li You can also enter a list of comma-separated tags in the provided box. This is, again, optional, but it's suggested that you do tag your quote, especially with #{link_to "tags that already exist", tags_quotes_path}, though creating new tags is not frowned upon. +%h3 Your Quote += form_for @quote do |f| + - if @quote.errors.any? + #error-messages + %h4 Errors were found! + %ul + - @quote.errors.full_messages.each do |msg| + %li= msg + .form-field= f.text_area :content + .form-field Your username (optional): #{f.text_field :submitter} + .form-field Notes (optional): + .form-field= f.text_area :notes + .form-field + Tags (optional): + .tags-input= f.text_field :tag_list, type: :tags, value: f.object.tag_list.join(",") + .form-field= f.submit diff --git a/config/routes.rb b/config/routes.rb index 33cc5f3..493102b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -59,6 +59,7 @@ Rails.application.routes.draw do collection do get 'latest' get 'top' + get 'random' get 'tags' get 'tags/:id', :action => "tag", :as => "tag" end -- cgit 1.4.1