Skip to content

Commit

Permalink
Merge pull request #461 from mehulkar/create-suggeston
Browse files Browse the repository at this point in the history
Create suggeston
  • Loading branch information
mehulkar committed Jun 6, 2015
2 parents ead39f2 + b3ea36e commit 25c3766
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 70 deletions.
29 changes: 2 additions & 27 deletions app/controllers/cities_controller.rb
@@ -1,38 +1,13 @@
class CitiesController < ApplicationController
before_action :set_city, except: [:index, :new, :index, :forbes_new, :forbes_create]
before_action :set_city, except: [:index, :new, :index]
before_action :authenticate_user!, :authorized?, only: [:new, :create, :edit, :update, :destroy]
before_action :away_ye_waitlisted, except: [:index, :forbes_show, :forbes_new, :forbes_suggest, :forbes_create, :forbes_set_city]
before_action :away_ye_waitlisted, except: [:index, :forbes_show, :forbes_set_city]

# GET /cities
def index
use_new_styles
end

def forbes_new
use_new_styles
if current_user
@city = City.new
else
flash[:notice] = 'Sign up first so we can let you know when your city is approved!'
redirect_to sign_up_path
end
end

def forbes_create
#NOTE: Seems unnecessary but required for the error case
use_new_styles

@city = NewSuggestedCity.call(city_params, current_user)

respond_to do |format|
if @city.persisted?
format.html { redirect_to forbes_city_path(@city), notice: 'We\'ve gotten your submission and will get to it ASAP.' }
else
format.html { render :forbes_new, alert: "Something went wrong! Our fault. Could you try again?" }
end
end
end

def forbes_set_city
current_user.update(home_city: @city)
redirect_to forbes_city_path(@city)
Expand Down
26 changes: 26 additions & 0 deletions app/controllers/city_suggestions_controller.rb
@@ -0,0 +1,26 @@
class CitySuggestionsController < ApplicationController
def new
use_new_styles
if current_user
@city = City.new
else
flash[:notice] = 'Sign up first so we can let you know when your city is approved!'
redirect_to sign_up_path
end
end

def create
use_new_styles
@city = NewSuggestedCity.call(city_params, current_user)
if @city.persisted?
redirect_to forbes_city_path(@city), notice: 'We\'ve gotten your submission and will get to it ASAP.'
else
render :new, alert: "Something went wrong! Our fault. Could you try again?"
end
end

private
def city_params
params.require(:city).permit!
end
end
17 changes: 0 additions & 17 deletions app/views/cities/_user_form.html.haml

This file was deleted.

24 changes: 0 additions & 24 deletions app/views/cities/forbes_new.html.erb

This file was deleted.

48 changes: 48 additions & 0 deletions app/views/city_suggestions/new.html.erb
@@ -0,0 +1,48 @@
<div class="light-background">
<%= render 'shared/header' %>

<div class='container'>
<div class="cities-partial">
<div class="city-cta-header">
<h1 class="dark center">Let's bring TWS to new lands!</h1>
<p class="header-small">If you didn’t find your city in the list before, add it here!</p>
</div>
<div class="submit-city-container">
<%= form_for @city, html: {class: 'dummy new_city'}, url: suggest_create_cities_path do |f| %>
<%= f.text_field :name, placeholder: 'Your city or college name' %>
<%= f.submit 'Submit', data: { confirmation: false }, class: 'save-city' %>
<% end %>
<div class="city-confirmation-text">
<h2 class="confirm-message">
Double check your spelling! And make sure it’s just the city or school name.
</h2>
<p>
After you confirm, we’ll make sure everything checks out and email you
when your friends and neighbors can join you for Tea With Strangers.
</p>
</div>
<% if @city.errors.any? %>
<div id="error_explanation">
<h2><%="#{pluralize(@city.errors.count, "error")} prohibited this city from being saved:"%></h2>
<ul>
<%= @city.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
</div>
<div class="active-city-list">
<h3 class="capitalize center current-cities-header">Or click your city below if we're already there</h3>
<div class="cities-list">
<% City.visible.each do |c| %>
<div class="city no-photo">
<%= link_to c.name, forbes_city_path(c) %>
</div>
<% end %>
</div>
</div>
</div>
</div>
<%= render partial: 'shared/new_footer' %>
</div>
4 changes: 2 additions & 2 deletions config/routes.rb
Expand Up @@ -40,8 +40,8 @@

resources :cities do
collection do
get '/suggest' => 'cities#forbes_new', as: :suggest
post '/suggest' => 'cities#forbes_create', as: :suggest_create
get '/suggest' => 'city_suggestions#new', as: :suggest
post '/suggest' => 'city_suggestions#create', as: :suggest_create
end
member do
get '/host/:host_id' => 'hosts#show', as: :host
Expand Down

0 comments on commit 25c3766

Please sign in to comment.