Skip to content

Commit

Permalink
Merge pull request #5 from BrandiPhillips/playing_with_dropdowns
Browse files Browse the repository at this point in the history
Added dropdowns, DRYed forms, and modified login
  • Loading branch information
eabrash committed Oct 6, 2016
2 parents 6a7aa39 + c7dcfd1 commit 7f3e112
Show file tree
Hide file tree
Showing 15 changed files with 5,234 additions and 73 deletions.
5 changes: 4 additions & 1 deletion app/controllers/markets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ def show

def new
@market = Market.new
@method = 'post'
@path = markets_create_path
end

def create
@market = Market.create(name: params[:market][:name], address: params[:market][:address], city: params[:market][:city], county: params[:market][:county], state: params[:market][:state], zip: params[:market][:zip])

end

def edit
@market = Market.find(params[:id])
@method = 'put'
@path = markets_update_path(@market.id)
end

#{}"market"=>{"name"=>"Quincy Farmers Market", "address"=>"0 Denis Ryan Parkway", "city"=>"Quincy", "county"=>"Norfolk", "state"=>"Massachusetts", "zip"=>"21690"}
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def show

def new
@product = Product.new
@method = 'post'
@path = products_create_path
end

def create
Expand All @@ -16,6 +18,8 @@ def create

def edit
@product = Product.find(params[:id])
@method = 'put'
@path = products_update_path
end

def update
Expand Down
25 changes: 14 additions & 11 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
class SessionsController < ApplicationController
def index
case :user_type
when 'user'
redirect_to users_search_path
when 'market'
redirect_to create_session_path
when 'vendor'
redirect_to create_session_path
end

end

def new
if params[:user_type] == 'user'
user = {type: params[:user_type], id: nil}
log_in (user)
puts current_user.id
redirect_to users_index_path
end

@type = params[:user_type]
end

def create
user = {type: params[:session][:type], id: params[:session][:id]}

user = {type: params[:user_type], id: params[:session][:id]}
log_in (user)
if params[:session][:type].downcase == "market"
if params[:user_type].downcase == "market"
redirect_to markets_index_path
elsif params[:session][:type].downcase == "vendor"
elsif params[:user_type].downcase == "vendor"
redirect_to vendors_index_path
else
redirect_to users_index_path
end

end

def destroy
Expand Down
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class UsersController < ApplicationController
def index
@market = Market.new
@markets = Market.all
end

Expand Down
14 changes: 13 additions & 1 deletion app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
module SessionsHelper

class User

def initialize

end

def id
return nil
end

end

def log_in(user)
session[:user_type] = user[:type].downcase
session[:user_id] = user[:id].to_i
Expand All @@ -11,7 +23,7 @@ def current_user
elsif session[:user_type] == "market"
@current = Market.find(session[:user_id])
else
@current = 'user'
@current = User.new
end

return @current
Expand Down
21 changes: 21 additions & 0 deletions app/views/markets/_marketform.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%= form_for @market, method: @method, url: @path do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :address %>
<%= f.text_field :address %>
<%= f.label :city %>
<%= f.text_field :city %>
<%= f.label :county %>
<%= f.text_field :county %>
<%= f.label :state %>
<%= f.text_field :state %>
<%= f.label :zip %>
<%= f.text_field :zip %>
<%= f.submit %>
<% end %>
23 changes: 3 additions & 20 deletions app/views/markets/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
<h1>Edit your market profile!</h1>

<p>Use the form below to edit your profile. When you are done, press submit!</p>

<section>
<%= form_for @market, method: 'put', url: markets_update_path(@market.id) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :address %>
<%= f.text_field :address %>
<%= f.label :city %>
<%= f.text_field :city %>
<%= f.label :county %>
<%= f.text_field :county %>
<%= f.label :state %>
<%= f.text_field :state %>
<%= f.label :zip %>
<%= f.text_field :zip %>

<%= f.submit %>
<% end %>
<%= render partial: "marketform" %>

</section>
20 changes: 1 addition & 19 deletions app/views/markets/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,7 @@
<p>Use the form below to create a new market. When you are done, press submit!</p>

<section>
<%= form_for @market, url: markets_create_path, method: :post do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :address %>
<%= f.text_field :address %>
<%= render partial: "marketform" %>

<%= f.label :city %>
<%= f.text_field :city %>
<%= f.label :county %>
<%= f.text_field :county %>
<%= f.label :state %>
<%= f.text_field :state %>
<%= f.label :zip %>
<%= f.text_field :zip %>
<%= f.submit %>
<% end %>
</section>
6 changes: 6 additions & 0 deletions app/views/products/_productform.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= form_for @product, method: @method, url: @path do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.submit %>
<% end %>
7 changes: 1 addition & 6 deletions app/views/products/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@
<p>Please edit the name of your new product in the space below. When you are finished, press submit!</p>

<section>
<%= form_for @product, method: 'put', url: products_update_path do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.submit %>
<% end %>
<%= render partial: "productform" %>
</section>
7 changes: 1 addition & 6 deletions app/views/products/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@
<p>Please enter the name of your new product in the space below. When you are finished, press submit!</p>

<section>
<%= form_for @product, method: 'post', url: products_create_path do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.submit %>
<% end %>
<%= render partial: "productform" %>
</section>
2 changes: 1 addition & 1 deletion app/views/sessions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<nav>
<ul>
<li>
<%= link_to "Guest Image", users_index_path(:user_type =>'user') %>
<%= link_to "Guest Image", sessions_new_path(:user_type => 'user') %>
</li>
<li>
<%= link_to "Market Image", sessions_new_path(:user_type => 'market') %>
Expand Down
17 changes: 9 additions & 8 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<h1>Welcome to FarMar!</h1>
<p>Please create a new session by entering your information:</p>
<h1>Welcome, <%= @type.capitalize %>!</h1>
<p>Please create a new session by identifying yourself using the dropdown:</p>

<%= form_for(:session, url: sessions_create_path) do |f| %>
<%= form_for(:session, url: sessions_create_path(:user_type => @type)) do |f| %>
<%= f.label :type %>
<%= f.text_field :type %>
<%= f.label :id %>
<%= f.text_field :id %>
<% if @type == 'market' %>
<%= f.collection_select :id, Market.all, :id, :name %>
<% elsif @type == 'vendor' %>
<%= f.collection_select :id, Vendor.all, :id, :name %>
<% end %>
<%= f.submit "Log in" %>
<% end %>
Binary file modified db/development.sqlite3
Binary file not shown.
Loading

0 comments on commit 7f3e112

Please sign in to comment.