Skip to content

Commit

Permalink
added global helper & modified underlying code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirv committed May 31, 2017
1 parent c907166 commit 9cdfe14
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 42 deletions.
5 changes: 4 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ def full_title(page_title = '')
end
end


def user?(user)
return true unless user.nil?
return false
end


def gravatar_for(user, options = { size: 80})
Expand Down
5 changes: 2 additions & 3 deletions app/helpers/recipes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ def is_owner?
end
end

def displayGravator?(user)
link_to gravatar_for(user, size: 100), user_path(user) unless user.nil?

def user?(user)
return true unless user.nil?
end

end
6 changes: 4 additions & 2 deletions app/views/recipes/_gravatar_section.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<%= displayGravator?(user) %>
<h5> User name: <%= user.first_name %></h5>
<p>
<%= link_to gravatar_for(user, size: 100), user_path(user) %>
<h5> User name: <%= user.first_name %></h5>
</p>
77 changes: 41 additions & 36 deletions app/views/recipes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,79 +21,84 @@
<div class="well" id="show-recipe">
<h3>Ingredients</h3>
<ul>
<%@recipe.ingredients.each do |ingredient| %>
<li><%= ingredient.name %></li><%end %>
<% @recipe.ingredients.each do |ingredient| %>
<li><%= ingredient.name %></li><% end %>
</ul>
<h3>Directions</h3>
<ol>
<%@recipe.directions.each do |direction| %>
<% @recipe.directions.each do |direction| %>
<li><%= direction.step %></li>
<%end %>
<% end %>
</ol>
<%if @recipe.styles.any? %>
<% if @recipe.styles.any? %>
<p>Styles: <%= render @recipe.styles %></p>
<%end %>
<%if @recipe.feeds.any? %>
<% end %>
<% if @recipe.feeds.any? %>
<p>Feeds: <%= render @recipe.feeds %></p>
<%end %>
<%if @recipe.preptimes.any? %>
<% end %>
<% if @recipe.preptimes.any? %>
<p>Preptime: <%= render @recipe.preptimes %></p>
<%end %>
<% end %>
<p><strong>Notes:</strong></p><%= simple_format(@recipe.description) %>
<div class="pull-right">
<%= link_to like_recipe_path(@recipe, like: true), :method => :post do %>
<i aria-hidden="true" class="fa fa-thumbs-o-up"></i> &nbsp;
<%= @recipe.thumbs_up_total %>
<%end %> &nbsp;&nbsp;&nbsp;&nbsp;
<% end %> &nbsp;&nbsp;&nbsp;&nbsp;
<%= link_to like_recipe_path(@recipe, like: false), method: :post do %>
<i aria-hidden="true" class="fa fa-thumbs-o-down"></i> &nbsp; <%= @recipe.thumbs_down_total %>
<%end %>
<% end %>
</div>
</div>
<%if logged_in? and is_owner? %>
<% if logged_in? and is_owner? %>
<%= link_to "Edit this Recipe", edit_recipe_path(@recipe), class: "btn btn-success pull-right edit" %>
<%end %>
<% end %>

<%if logged_in? and (is_owner?) %>
<% if logged_in? and (is_owner?) %>
<%= link_to "[Delete Recipe]", @recipe, method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger pull-right delete"%>
<%end %>
<% end %>
<div class="social-share-button">
Share this! <%= social_share_button_tag(@recipe.name) %>
</div>
</div>

<div class="col-md-5 pull-right">
<%= render partial: 'gravatar_section', locals: {user: @user} %>
<p></p><br>
<h3><br>
Reviews</h3>
<%if @recipe.reviews.any? %>
<%@recipe.reviews.each do |c| %>
<% if user?(@user) %>
<%= render partial: 'gravatar_section', locals: {user: @user} %>
<% end %>

<h3>Reviews</h3>
<% if @recipe.reviews.any? %>
<% @recipe.reviews.each do |c| %>
<div class="well">
<div class="col-md-2 pull-right">
<strong>User: <%= c.user.username.downcase.capitalize %></strong>
</div>
<p><%= c.body %></p><i><small><%= c.updated_at.strftime("%m/%d/%Y") %></small></i>
<%if c.user == current_user %>
<p><%= c.body %></p>
<i><small><%= c.updated_at.strftime("%m/%d/%Y") %></small></i>
<% if is_owner? %>
<%= link_to "Delete", review_recipe_path(:revid => c.id), class:"btn btn-danger btn-small pull-right", method: :delete, data: { confirm: "Are you sure you want to delete this review?" } %>
<%end %>
<% end %>
</div>
<%end %>
<% end %>
<%else %>

<h5>Be the first to post a review!</h5><%end %>
<h5>Be the first to post a review!</h5>
<% end %>
<div class="form-group">
<%= form_tag(review_recipe_path, :method=>'post') do %><%= text_area_tag "body", nil, size:"5x5", class:"form-control" %><%= submit_tag "Submit Review", class: "btn btn-primary" %><br>
<%= form_tag(review_recipe_path, :method=>'post') do %><%= text_area_tag "body", nil, size:"5x5", class:"form-control" %><%= submit_tag "Submit Review", class: "btn btn-primary" %>
<br>
<br>
</div><%end %>
<% end %>
</div>
<h4><i>You may also like:</i></h4>
<hr>
<%@random_recipe.each do |recipe| %>
<div class="row show-img">
<div class="image_wrapper hidden-xs-down">
<%=image_tag recipe.picture %>
</div><%= link_to recipe.name, recipe %><%= truncate(recipe.description, length: 150)%><small><%=link_to 'click to see more', recipe_path(recipe)%></small>
</div><%end %>
<% @random_recipe.each do |recipe| %>
<div class="row show-img">
<div class="image_wrapper hidden-xs-down">
<%=image_tag recipe.picture %>
</div><%= link_to recipe.name, recipe %><%= truncate(recipe.description, length: 150)%><small><%=link_to 'click to see more', recipe_path(recipe) %></small>
</div>
<% end %>
</div>
</div>
<div class="jumbotron">
Expand Down

0 comments on commit 9cdfe14

Please sign in to comment.