Skip to content

Commit

Permalink
Improve dishes#show
Browse files Browse the repository at this point in the history
  • Loading branch information
raghubetina committed Nov 28, 2016
1 parent bd7638c commit bed2a56
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 151 deletions.
3 changes: 1 addition & 2 deletions app/controllers/bookmarks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def update

@bookmark.dish_id = params[:dish_id]
@bookmark.venue_id = params[:venue_id]
@bookmark.user_id = params[:user_id]
@bookmark.notes = params[:notes]

save_status = @bookmark.save
Expand All @@ -73,7 +72,7 @@ def update

case referer
when "/bookmarks/#{@bookmark.id}/edit", "/update_bookmark"
redirect_to("/bookmarks/#{@bookmark.id}", :notice => "Bookmark updated successfully.")
redirect_to("/dishes/#{@bookmark.dish.id}", :notice => "Bookmark updated successfully.")
else
redirect_back(:fallback_location => "/", :notice => "Bookmark updated successfully.")
end
Expand Down
217 changes: 68 additions & 149 deletions app/views/dishes/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,162 +1,81 @@
<div class="page-header">
<h3>Dish #<%= @dish.id %></h3>
</div>

<div class="row">
<div class="col-md-12 mb-2">
<dl class="dl-horizontal">
<dt>Name</dt>
<dd><%= @dish.name %></dd>

<dt>Cuisine</dt>
<dd>
<% if @dish.cuisine.present? %>
<a href="/cuisines/<%= @dish.cuisine_id %>">
<%= @dish.cuisine.name %>
</a>
<% end %>
</dd>

</dl>

<div class="btn-group btn-group-justified">
<a href="/dishes" class="btn btn-primary">
Back
</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>
</div>
</div>
</div>

<!-- A Dish has many bookmarks -->

<div class="row">
<div class="col-md-12">
<ul class="list-group">
<li class="list-group-item list-group-item-info">
Bookmarks
</li>

<% @dish.bookmarks.each do |bookmark| %>
<li class="list-group-item">
<a href="/bookmarks/<%= bookmark.id %>">
<%= bookmark.notes %>
</a>
<div class="btn-group btn-group-xs pull-right">
<a href="/bookmarks/<%= bookmark.id %>" class="btn btn-primary">
<i class="fa fa-search-plus"></i>
</a>
<a href="/bookmarks/<%= bookmark.id %>/edit" class="btn btn-warning">
<i class="fa fa-edit"></i>
</a>
<a href="/delete_bookmark/<%= bookmark.id %>" class="btn btn-danger" rel="nofollow">
<i class="fa fa-trash-o"></i>
</a>
</div>
</li>
<% end %>

<li class="list-group-item">
<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 venue_id -->
<div class="form-group">
<label for="venue_id" class="control-label">
Venue
</label>

<%= select_tag(:venue_id, options_from_collection_for_select(Venue.all, :id, :name), :class => "form-control") %>
<div class="row mt-2">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
You loved the <%= @dish.name %> at...

<% if @dish.cuisine.present? %>
<span class="label label-primary pull-right">
<%= @dish.cuisine.name %>
</span>
<% end %>
</h4>
</div>

<!-- Label and input for user_id -->
<input type="hidden" name="user_id" value="<%= current_user.id %>">
<ul class="list-group">
<li class="list-group-item">
<form action="/create_bookmark" class="form-inline" 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 notes -->
<div class="form-group">
<label for="notes" class="control-label">
Notes
</label>

<textarea id="notes" name="notes" placeholder="Notes" class="form-control" rows="3"></textarea>
</div>
<input type="hidden" name="dish_id" value="<%= @dish.id %>">
<input type="hidden" name="user_id" value="<%= current_user.id %>">

<button class="btn btn-block btn-success">
Create Bookmark
</button>
</form>
</li>
</ul>
</div>
</div>
<!-- Label and input for venue_id -->
<div class="form-group">
<label for="venue_id" class="control-label sr-only">
Venue
</label>

<!-- A Dish has many fans -->
<%= select_tag(:venue_id, options_from_collection_for_select(Venue.all, :id, :name), :class => "form-control", :prompt => "Choose a venue...") %>
</div>

<div class="row">
<div class="col-md-12">
<ul class="list-group">
<li class="list-group-item list-group-item-info">
Fans
</li>
<button class="btn btn-primary btn">
<i class="fa fa-heart"></i>
</button>

<% @dish.fans.each do |user| %>
<li class="list-group-item">
<a href="/users/<%= user.id %>">
<%= user.username %>
</a>
<div class="btn-group btn-group-xs pull-right">
<a href="/users/<%= user.id %>" class="btn btn-primary">
<i class="fa fa-search-plus"></i>
</a>
<a href="/users/<%= user.id %>/edit" class="btn btn-warning">
<i class="fa fa-edit"></i>
</a>
<a href="/delete_user/<%= user.id %>" class="btn btn-danger" rel="nofollow">
<i class="fa fa-trash-o"></i>
</a>
</div>
<small class="pull-right text-muted">
right now
</small>
</form>
</li>
<% end %>
</ul>
</div>
</div>

<!-- A Dish has many specialists -->

<div class="row">
<div class="col-md-12">
<ul class="list-group">
<li class="list-group-item list-group-item-info">
Specialists
</li>
<% current_user.bookmarks.order(:created_at => :desc).where(:dish_id => @dish.id).each do |bookmark| %>
<li class="list-group-item">
<p>
<a href="/venues/<%= bookmark.venue_id %>">
<%= bookmark.venue.name %>
</a>

<small class="pull-right text-muted">
<%= time_ago_in_words(bookmark.created_at) %> ago

<a href="/bookmarks/<%= bookmark.id %>/edit">
<i class="fa fa-fw fa-edit"></i>
</a>

<a href="/delete_bookmark/<%= bookmark.id %>">
<i class="fa fa-fw fa-trash-o"></i>
</a>
</small>
</p>

<% if bookmark.notes.present? %>
<p>
<%= bookmark.notes %>
</p>
<% end %>
</li>
<% end %>
</ul>

<% @dish.specialists.each do |venue| %>
<li class="list-group-item">
<a href="/venues/<%= venue.id %>">
<%= venue.name %>
</a>
<div class="btn-group btn-group-xs pull-right">
<a href="/venues/<%= venue.id %>" class="btn btn-primary">
<i class="fa fa-search-plus"></i>
</a>
<a href="/venues/<%= venue.id %>/edit" class="btn btn-warning">
<i class="fa fa-edit"></i>
</a>
<a href="/delete_venue/<%= venue.id %>" class="btn btn-danger" rel="nofollow">
<i class="fa fa-trash-o"></i>
</a>
</div>
</li>
<% end %>
</ul>
<div class="panel-footer text-center">
<a href="/dishes" class="btn btn-block btn-default">
<i class="fa fa-chevron-left"></i>
</a>
</div>
</div>
</div>
</div>

0 comments on commit bed2a56

Please sign in to comment.