Skip to content

Commit

Permalink
merging emails
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-schleicher committed Dec 23, 2016
2 parents fa86abd + 0dbdf35 commit 943bcc5
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 9 deletions.
14 changes: 14 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ def create
flash[:warning] = "We were unable to add your email to our mailing list."
redirect_back(fallback_location: legislators_path)
end
end

def edit
@user = User.find(params[:id])
end

def destroy
@user = User.find(params[:id])
if @user.destroy
flash[:success] = "We've removed your email from the subscriber list"
redirect_to root_path
else
flash[:error] = "No email address found"
redirect_to root_path
end
end

private
Expand Down
3 changes: 3 additions & 0 deletions app/views/user_mailer/weekly_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
<% end %>
<% end %>
<%= link_to "Unsubscribe", edit_user_url(@user) %>

3 changes: 3 additions & 0 deletions app/views/user_mailer/weekly_email.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ Here's how your lawmakers voted this week:
<% end %>
<% end %>
<%= link_to "Unsubscribe", edit_user_url(@user) %>

4 changes: 3 additions & 1 deletion app/views/user_mailer/welcome.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h1>Welcome to the Congress Tracker app</h1>

<p>Stay tuned for weekly updates about your representatives in Congress.</p>
<p>Stay tuned for weekly updates about your representatives in Congress.</p>

<%= link_to "Unsubscribe", edit_user_url(@user) %>
4 changes: 3 additions & 1 deletion app/views/user_mailer/welcome.text.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Welcome to the Congress Tracker app

Stay tuned for weekly updates about your representatives in Congress.
Stay tuned for weekly updates about your representatives in Congress.

<%= link_to "Unsubscribe", edit_user_url(@user) %>
3 changes: 3 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Are you sure you want to unsubscribe?</h1>

<%= link_to "Yes, please unsubscribe me", user_path(@user), method: :delete %>
1 change: 1 addition & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
config.active_record.migration_error = :page_load

config.action_mailer.delivery_method = :letter_opener
config.action_mailer.default_url_options = { :host => 'localhost:3000' }

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

root 'sessions#new'

resources :users, only: [:create]
resources :users, only: [:create, :edit, :destroy]
resources :legislators, param: :bioguide_id
resources :bills, param: :bill_id
resource :session, only: [:new, :create, :destroy]
Expand Down
4 changes: 1 addition & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@

create_table "bills", force: :cascade do |t|
t.string "official_title"
t.string "popular_title"
t.text "summary_short"
t.date "introduced_on"
t.date "last_vote_at"
t.text "keywords"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "bill_id"
t.boolean "enacted"
t.string "sponsor_id"
t.boolean "enacted"
end

create_table "delayed_jobs", force: :cascade do |t|
Expand Down
8 changes: 5 additions & 3 deletions lib/tasks/scheduler.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
desc "This weekly email task is called by the Heroku scheduler add-on"

task :weekly_emails => :environment do
puts "Sending emails..."
User.send_weekly_emails
puts "Emails sent"
if Date.today.monday?
puts "Sending emails..."
User.send_weekly_emails
puts "Emails sent"
end
end

0 comments on commit 943bcc5

Please sign in to comment.