-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
127 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.interest { | ||
margin-top: $base-spacing; | ||
} | ||
|
||
.new_interest { | ||
display: flex; | ||
align-items: stretch; | ||
|
||
.btn { | ||
flex: 0 0 auto; | ||
margin-bottom: $small-spacing; | ||
} | ||
|
||
.email { | ||
flex: 1 0 auto; | ||
margin-right: $small-spacing; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
.timer, | ||
.timer-explanation { | ||
.timer { | ||
font-family: 'Source Sans Pro', sans-serif; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
class InterestsController < ApplicationController | ||
def create | ||
@interest = Interest.new(interest_params) | ||
|
||
if @interest.save | ||
redirect_back( | ||
fallback_location: root_path, | ||
notice: t("interest.create.success"), | ||
) | ||
else | ||
redirect_back( | ||
fallback_location: root_path, | ||
alert: t("interest.create.failure"), | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def interest_params | ||
params.require(:interest).permit(:email) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
module ApplicationHelper | ||
def expiration_time | ||
Post.order(created_at: :desc).first.created_at + 7.days | ||
if Post.any? | ||
Post.order(created_at: :desc).first.created_at + 7.days | ||
else | ||
Time.current | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Interest < ApplicationRecord | ||
validates :email, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="interest"> | ||
<h2>Want a self-destructing blog of your own?</h2> | ||
|
||
<p> | ||
Let me know. | ||
If enough people want a blog of their own like this, | ||
I'll turn it into something that anyone can use. | ||
</p> | ||
|
||
<%= simple_form_for(@interest || Interest.new) do |form| %> | ||
<%= form.input :email, label: false, placeholder: "Email" %> | ||
<%= form.button :submit %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
Rails.application.routes.draw do | ||
resources :posts | ||
resources :interests, only: [:create] | ||
|
||
root to: "posts#index" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateInterests < ActiveRecord::Migration[5.0] | ||
def change | ||
create_table :interests do |t| | ||
t.string :email, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "rails_helper" | ||
|
||
feature "Register interest" do | ||
scenario "successfully" do | ||
visit root_path | ||
|
||
fill_in "Email", with: "[email protected]" | ||
click_on "I want in." | ||
|
||
expect(page).to have_content t("interest.create.success") | ||
expect(Interest.last.email).to eq("[email protected]") | ||
end | ||
|
||
scenario "unsuccessfully" do | ||
visit root_path | ||
|
||
click_on "I want in." | ||
|
||
expect(page).to have_content t("interest.create.failure") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Interest, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |