Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/dishes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ class DishesController < ApplicationController
def index
@q = Dish.ransack(params[:q])
@dishes = @q.result(:distinct => true).includes(:cuisine, :bookmarks, :fans, :specialists).page(params[:page]).per(10)

render("dishes/index.html.erb")
@bookmark = Bookmark.new
end


def show
@bookmark = Bookmark.new
@dish = Dish.find(params[:id])
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/venues_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class VenuesController < ApplicationController
def index
@q = Venue.ransack(params[:q])
@user_venue=current_user.bookmarked_venues
@q = @user_venue.ransack(params[:q])
@venues = @q.result(:distinct => true).includes(:bookmarks, :neighborhood, :fans, :specialties).page(params[:page]).per(10)
@location_hash = Gmaps4rails.build_markers(@venues.where.not(:address_latitude => nil)) do |venue, marker|
marker.lat venue.address_latitude
Expand Down
2 changes: 2 additions & 0 deletions app/models/dish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Dish < ApplicationRecord
:counter_cache => true

# Indirect associations


has_many :specialists,
:through => :bookmarks,
Expand All @@ -17,6 +18,7 @@ class Dish < ApplicationRecord
:through => :bookmarks,
:source => :user


# Validations

validates :name, :uniqueness => { :case_sensitive => false }
Expand Down
87 changes: 68 additions & 19 deletions app/views/dishes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Dishes
<a href="/dishes/new" class="btn btn-lg btn-success">New Dish</a>
</h1>
</div><div class="row mb-1">
</div>
<div class="row mb-1">
<div class="col-md-12">
<%= search_form_for @q, :class => "collapse", :id => "dishes_filters" do |f| %>
<p class="lead">Narrow results:</p>
Expand Down Expand Up @@ -53,10 +54,16 @@
});
</script>

<div class="form-group">
<%= f.label :cuisine_name_cont, "Cuisine name contains" %>
<%= f.text_field :cuisine_name_cont, :class => "form-control", :placeholder => "Cuisine name contains" %>
</div>

<div class="form-group">
<%= "Cuisines" %>
<% Cuisine.all.each do |cuisine| %>
<label>
<%= check_box_tag('q[cuisine_id_eq_any][]', cuisine.id, (true if @q.cuisine_id_eq_any.try(:include?, cuisine.id))) %>
<%= cuisine.name %>
</label>
<% end %>
</div>

<div class="form-group">
<%= f.label :bookmarks_notes_cont, "Bookmark notes contains" %>
Expand Down Expand Up @@ -87,29 +94,71 @@
<div class="col-md-12">
<table class="table table-striped table-hover">
<tr>
<th>Name</th>
<th>Cuisine</th>
<th>Actions</th>
<th>The very best...</th>
<th>is at...</th>
<th></th>
</tr>

<% @dishes.each do |dish| %>
<tr>
<td><%= dish.name %></td>
<% @dishes.each do |dish| %>
<td>
<% if dish.cuisine.present? %>
<a href="/cuisines/<%= dish.cuisine.id %>">
<%= dish.cuisine.name %>
<% if dish.name.present? %>
<a href="/dishes/<%= dish.id %>">
<%= dish.name %>
</a>
<% end %>
</td>

<td>
<a href="/dishes/<%= dish.id %>" class="btn btn-primary">Show</a>
<a href="/dishes/<%= dish.id %>/edit" class="btn btn-warning">Edit</a>
<a href="/delete_dish/<%= dish.id %>" class="btn btn-danger" rel="nofollow">Delete</a>
<% if dish.specialists.present? %>
<% dish.specialists.each do |venue| %>
<a href="/venues/<%= venue.id %>">
<%= venue.name %></a>
<% end %>

<% else %>

<form action="/create_bookmark" method="post">
<!-- Hidden input for authenticity token to protect from forgery -->
<input name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>">

<!-- Label and input for dish_id -->
<input type="hidden" name="dish_id" value="<%= dish.id %>">

<!-- Label and input for user_id -->
<input type="hidden" name="user_id" value="<%= current_user.id %>">

<!-- Label and input for venue_id -->
<div class="form-group">
<label for="venue_id" class="control-label sr-only">
Venue
</label>

<div style="display:inline-block">
<%= select_tag(:venue_id, options_from_collection_for_select(Venue.all.sort_by {|venue| venue.name}, :id, :name, @bookmark.venue_id), prompt:"Choose a venue...", :class => "form-control input-sm") %>
</div>

<button class="btn btn-primary btn-sm">
<i class="fa fa-heart"></i>
</button>
</form>
<% end %>
</td>

<td>
<% if dish.cuisine.present? %>
<a href="/cuisines/<%= dish.cuisine.id %>">
<%= dish.cuisine.name %>
<% end %>
</td>
</tr>
<% end %>
</table>
<%= paginate @dishes, theme: 'twitter-bootstrap-4' %>


<div>
<a href="/venues/new" class="btn btn-lg btn-success">Add a new venue</a>
</div>


</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/dishes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<% @dish.specialists.each do |venue| %>
<li class="list-group-item">
<a href="/venues/<%= venue.id %>">
<%= venue.name %>
<p><%= venue.name %></p>
</a>
<div class="btn-group btn-group-xs pull-right">
<a href="/venues/<%= venue.id %>" class="btn btn-primary">
Expand Down
10 changes: 6 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="/bookmarks">Bookmarks</a></li>

<li><a href="/dishes">Dishes</a></li>
<li><a href="/cuisines">Cuisines</a></li>
<li><a href="/neighborhoods">Neighborhoods</a></li>
<li><a href="/venues">Venues</a></li>
<li><a href="/users">Users</a></li>
<li><a href="/rails/info">Sitemap</a></li>
</ul>

<ul class="nav navbar-nav navbar-right">
Expand All @@ -57,7 +55,11 @@
<%= current_user.username %>
</a>
</li>

<li>
<a href="/bookmarks">
Bookmarks
</a>
</li>
<li>
<a href="/users/sign_out" data-method="delete" rel="nofollow">
Sign Out
Expand Down
4 changes: 2 additions & 2 deletions app/views/venues/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</script>

<div class="form-group">
<%= f.label :bookmarks_notes_cont, "Bookmark notes contains" %>
<%= f.label :bookmarks_notes_cont, "Bookmarked notes contains" %>
<%= f.text_field :bookmarks_notes_cont, :class => "form-control", :placeholder => "Bookmark notes contains" %>
</div>

Expand All @@ -69,7 +69,7 @@
</div>

<div class="form-group">
<%= f.label :specialties_name_cont, "Dish name contains" %>
<%= f.label :specialties_name_cont, "Bookmarked dish name contains" %>
<%= f.text_field :specialties_name_cont, :class => "form-control", :placeholder => "Dish name contains" %>
</div>

Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Rails.application.routes.draw do
root :to => "venues#index"
# Routes for Homepage link to /dishes page:
root "dishes#index"

# Routes for the Bookmark resource:
# CREATE
Expand Down
2 changes: 1 addition & 1 deletion grades.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
submission_url: https://grades.firstdraft.com
project_token: ''
personal_access_token:
personal_access_token: YMhoFUZydkV3ShNpanUydTYz
5 changes: 5 additions & 0 deletions whitelist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
- 127.0.0.1
- 10.240.0.0/16
- "::1"
- 192.157.77.90
- 128.135.98.68
- 141.117.117.96
- 104.234.44.158
- 208.72.125.2