about summary refs log tree commit diff stats
path: root/app
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-10-21 00:55:24 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-10-21 00:55:24 -0400
commit5dddde5dee7beecfb6824b208c4fb86c781a27f9 (patch)
treeca3c8f15020d889c8aeb4ebcb9ba102abee98923 /app
parent96813a5e508a54257ef03be613a704f1f71af53d (diff)
downloadthoughts-5dddde5dee7beecfb6824b208c4fb86c781a27f9.tar.gz
thoughts-5dddde5dee7beecfb6824b208c4fb86c781a27f9.tar.bz2
thoughts-5dddde5dee7beecfb6824b208c4fb86c781a27f9.zip
Added quote submission (and random)
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/quotes.css.scss2
-rw-r--r--app/controllers/quotes_controller.rb28
-rw-r--r--app/views/layouts/quotes.html.haml3
-rw-r--r--app/views/quotes/new.html.erb2
-rw-r--r--app/views/quotes/new.html.haml24
5 files changed, 57 insertions, 2 deletions
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 @@
1/* 1/*
2 *= require normalize-rails 2 *= require normalize-rails
3 *= require tags-input
4 *= require jquery-ui
3 *= require_tree ./quotes 5 *= require_tree ./quotes
4 */ 6 */
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
26 end 26 end
27 end 27 end
28 28
29 def random
30 picked = Quote.ids.sample
31 redirect_to quote_url(picked)
32 end
33
29 def tags 34 def tags
30 @tags = Quote.published.tag_counts_on(:tags) 35 @tags = Quote.published.tag_counts_on(:tags)
31 end 36 end
@@ -51,6 +56,23 @@ class QuotesController < ApplicationController
51 end 56 end
52 57
53 def new 58 def new
59 @quote = Quote.new
60 end
61
62 def create
63 @quote = Quote.new(quote_params)
64 @quote.submitter = nil if @quote.submitter.empty?
65
66 if user_signed_in?
67 @quote.state = :published
68 @quote.save!
69
70 flash[:notice] = "Thank you for submitting your quote!"
71 redirect_to @quote
72 else
73 flash[:error] = "There was an error."
74 render :new
75 end
54 end 76 end
55 77
56 def upvote 78 def upvote
@@ -94,4 +116,10 @@ class QuotesController < ApplicationController
94 end 116 end
95 end 117 end
96 end 118 end
119
120 private
121
122 def quote_params
123 params.require(:quote).permit(:content, :notes, :submitter, :tag_list)
124 end
97end 125end
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 @@
18 %li= link_to_unless_current "Home", quotes_url 18 %li= link_to_unless_current "Home", quotes_url
19 %li= link_to_unless_current "Latest", latest_quotes_url 19 %li= link_to_unless_current "Latest", latest_quotes_url
20 %li= link_to_unless_current "Top", top_quotes_url 20 %li= link_to_unless_current "Top", top_quotes_url
21 %li= link_to "Random", random_quotes_url
22 - if user_signed_in?
23 %li= link_to_unless_current "Submit", new_quote_url
21 %li= link_to_unless_current "Tags", tags_quotes_url 24 %li= link_to_unless_current "Tags", tags_quotes_url
22 %li= link_to_unless_current "Feed", latest_quotes_url(:atom) 25 %li= link_to_unless_current "Feed", latest_quotes_url(:atom)
23 .cleardiv 26 .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 @@
1<h1>Quotes#new</h1>
2<p>Find me in app/views/quotes/new.html.erb</p>
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 @@
1%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:
2%ul
3 %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.
4 %li Make sure to remove timestamps, if present in your quote, before submitting.
5 %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.
6 %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.
7 %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.
8 %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.
9%h3 Your Quote
10= form_for @quote do |f|
11 - if @quote.errors.any?
12 #error-messages
13 %h4 Errors were found!
14 %ul
15 - @quote.errors.full_messages.each do |msg|
16 %li= msg
17 .form-field= f.text_area :content
18 .form-field Your username (optional): #{f.text_field :submitter}
19 .form-field Notes (optional):
20 .form-field= f.text_area :notes
21 .form-field
22 Tags (optional):
23 .tags-input= f.text_field :tag_list, type: :tags, value: f.object.tag_list.join(",")
24 .form-field= f.submit