I get this error: app/views/topics/show.html.erb:49: syntax error, unexpected keyword_ensure, expecting keyword_end. I don't have a line 49. I checked to see if I was missing any <% end %> and I find that I don't.
<h1><%= #topic.name %></h1>
<% if user_is_authorized_for_topics? || if user.moderator? %>
<%= link_to "Edit Topic", edit_topic_path, class: 'btn btn-success' %>
<% end %>
<% if user_is_authorized_for_topics?%>
<%= link_to "Delete Topic", #topic, method: :delete, class: 'btn btn-danger', data: { confirm: 'Are you sure you want to delete this topic?' } %>
<% end %>
<div class="row">
<div class="col-md-8">
<p class="lead"><%= #topic.description %></p>
<% #topic.posts.each do |post| %>
<div class="media">
<div class="media-body">
<h4 class="media-heading">
<%= link_to post.title, topic_post_path(#topic, post) %>
</h4>
<small>
submitted <%= time_ago_in_words(post.created_at) %> ago by <%= post.user.name %> <br>
<%= post.comments.count %> Comments
</small>
</div>
</div>
<% end %>
<% #topic.sponsored_posts.each do |sponsored_post| %>
<div class="media">
<div class="media-body">
<h4 class="media-heading">
<%= link_to sponsored_post.title, topic_sponsored_post_path(#topic, sponsored_post) %>
</h4>
<small>
submitted <%= time_ago_in_words(sponsored_post.created_at) %> ago <br>
</small>
</div>
</div>
<% end %>
</div>
<% if current_user %>
<div class="col-md-4">
<%= link_to "New Post", new_topic_post_path(#topic), class: 'btn btn-success' %>
</div>
<% end %>
</div>
Probably this line:
<% if user_is_authorized_for_topics? || if user.moderator? %>
You only need if once, like this:
<% if user_is_authorized_for_topics? || user.moderator? %>
Related
I completed a search and found this topic that is close, How do I make simple form to use, I'm too new to fully understand
what I was looking at.
The answer was as follows:
Step 1
rails generate simple_form:install --bootstrap (which I did after adding the Gem and running Bundle Install)
Step 2
Told me to add wrappers (not sure if I need to complete this step)
Step 3
modify the simple_form and has this example:
<%= simple_form_for(#contact, url: supplier_contacts_path, html: { class:
'form-horizontal' }) do |f| %>
<div class="form-inputs">
<%= f.input :c_regular,wrapper: :horizontal_input_group do %>
<span class="input-group-addon">$</span>
<%= f.input_field :c_regular, :label => "Regular",class: "form-control" %>
<% end %>
</div>
<% end %>
My code is as follows(views/comments/show.html.erb):
<div id="comments">
<%= render :partial => #link.comments %>
</div>
<%= simple_form_for(#link, html {class: 'form-horizontal' }) do |f| %>
<div class="field">
<%= f.text_area :body, size: "60x12" %>
</div>
<%= f.submit "Add Comment", class: 'btn btn-primary" %>
<% end %>
Here's my partial(views/comments/_comments.html.erb):
<%= div_for(comment) do %>
<div class="comments_wrapper clearfix">
<div class="pull-left">
<p class="lead"><%= comment.body %></p>
<p><small>Submitted <strong><%= time_ago_in_words(comment.created_at) %>
ago</strong> by
<%= comment.user.email %></small></p>
</div>
<div class="btn-group pull-right">
<% if comment.user == current_user %>
<%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you
sure?' }, class: "btn btn-sm btn-default" %>
<% end %>
<% end %>
</div>
<% end %>
so my question is how can i enable this piece of code only when i want? I have multiple pages and some pages i need to remove that piece of code.
This is my current partial _navbar.html.erb and div.spotlight is the piece of code i need to disable in some pages
<div class="container">
<nav class="logonav">
<div class="row">
<div class="col50"><span class="logo"></span>
<h2>Musicus</h2>
<p>De ti para o mundo</p>
</div>
<% if user_signed_in? %>
<div class="col50">
<%= link_to 'Logout', destroy_user_session_path, class: 'ui-btn btn-normal', method: :delete %>
</div>
<% else %>
<div class="col50">
<%= link_to new_user_registration_path, class: 'ui-btn btn-accent' do %>
<span class="icon-add-user"></span> Criar Conta
<% end %>
<%= link_to new_user_session_path, class: 'ui-btn btn-normal' do %>
<span class="icon-login"></span> Login
<% end %>
</div>
<% end %>
</div>
</nav>
<div class="spotlight">
<%= yield :other_message %>
<%= render 'search' %>
<%= yield :primary_message %>
</div>
<%= yield :other_nav %>
</div>
You can use a simple if statement:
<% if show_spotlight %>
<div class="spotlight">
<%= yield :other_message %>
<%= render 'search' %>
<%= yield :primary_message %>
</div>
<% end %>
I have a blog rails app where users can comment on an article and the article author can message the user directly from the comment for which i have added a send message button, i am using mailbox for getting the message option, everything is working but the problem is when there are multiple comments the message button also get multiplied, but i don't want that what i am trying to have is one message button for each comment.
This is what am getting right now:
my code
<div id="comments">
<h2 class="comment_count">
<%= pluralize(#shipment.comments.count, "Bid") %>
</h2>
<% #comments.each do |comment| %>
<div class="comment">
<li class="round-image-50"><%= image_tag(current_user.avatar.url(:thumb)) %></li><h6 class="username"><strong><font style="text-transform: capitalize;"><%= comment.user.full_name %></strong></font></h6>
<div class="shipment">
<p class="content">
<div class="text-center left col-md-4">
<%= comment.content %>
</div>
<% if #shipment.user == current_user %>
<% #shipment.comments.each do |comment| %>
<%= link_to 'Send Message', new_conversation_path(recipient_id: comment.user_id), class: "btn btn-default btn-xs" %>
<% end %>
<% end %>
</p>
</div>
</div>
<% end %>
<%= render "comments/form" %>
</div>
Change this:
<% if #shipment.user == current_user %>
<% #shipment.comments.each do |comment| %>
<%= link_to 'Send Message', new_conversation_path(recipient_id: comment.user_id), class: "btn btn-default btn-xs" %>
<% end %>
<% end %>
to
<% if #shipment.user == current_user %>
<%= link_to 'Send Message', new_conversation_path(recipient_id: comment.user_id), class: "btn btn-default btn-xs" %>
<% end %>
PS: I assumed that #comments is same as #shipment.comments from your shown code
I am working on creating a test shoe store website for one of my classes. I had previously added a comment section and rating system for new shoes. For some reason the comment and rating section is no longer viewable.
Here is my product show page
<p id="notice"><%= notice %></p>
<div class="show-buttons" id="show1">
<%= link_to 'Edit', edit_product_path(#product), class: "btn btn- success btn-xs" %> |
<%= link_to 'Back', products_path, class: "btn btn-primary btn-xs" %>
</div>
<div class="pay button">
<%= form_tag "/payments/create" do %>
<%= render partial: "shared/stripe_checkout_button" %>
<%= hidden_field_tag(:product_id, #product.id) %>
</div>
<p>
<strong>Name:</strong>
<%= #product.name %>
</p>
<p>
<strong>Description:</strong>
<%= #product.description %>
</p>
<p>
<strong>Image url:</strong>
<%= #product.image_url %>
</p>
<p>Average Rating:
<div class="rated" data-score="<%= #product.average_rating %>"></div>
</p>
<%= render 'new_comment' %>
<%= render 'comment' %>
<%= will_paginate #comments %>
</div>
<% end %>
Here is my _comment.html.erb
<div class="container">
<div class="row">
<div class="product-reviews">
<% #comments.each do |comment| %>
<div class="row">
<hr>
<p><%= comment.user.first_name %> <small><em><%= "# {time_ago_in_words(comment.created_at)} ago" %></em></small></p>
<% if signed_in? && current_user.admin? %>
<%= link_to ('<span class="glyphicon glyphicon-remove"> </span>').html_safe, product_comment_path(#product, comment), method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>
<div class="rated" data-score="<%= comment.rating %>"></div>
<p><%= "Rating: #{comment.rating}/5" %></p>
<p><%= comment.body %></p>
</div>
<% end %>
</div>
</div>
My _new_comment.html.erb
<% if signed_in? %>
<h4>Add a review:</h4>
<%= form_for([#product, #product.comments.build]) do |f| %>
<p>
<%= f.label :body, "Comments" %><br>
<%= f.text_area :body %>
</p>
<p>
<%= f.label :rating %><br>
<div class= "rating"></div>
</p>
<%= f.submit "Submit", class: "btn btn-default" %>
</p>
<% end %>
<% end %>
And finally my product.html.erb
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="productbox">
<div class="imgthumb img-responsive">
<%= image_tag(product.image_url, :class => 'list_image') %>
</div>
<div class="caption">
<h3><%= product.name %></h3>
</div>
</div><!--end productbox-->
</div><!--end columns-->
<div class="col-md-8" id="descriptionp">
<p><%= product.description %><br><br>
<%= product.color %><br><br>
€<%= product.price %><br><br>
<%= link_to 'More Info', product %><br><br>
<% if signed_in? && current_user.admin? %>
<%= link_to 'Edit', edit_product_path(product) %> |
<%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>
</p>
</div>
</div><!--/row-->
</div><!--/container -->
<hr>
Any assistance on why I can no longer view my comments or rating page would be greatly appreciated.
I've been able to jump most hurtles as I move through the Hartl Rails tutorial, but I can't figure out what I'm doing wrong around 10.4. I can get everything to render correctly using this /static_pages/home.html.erb
<% if signed_in? %>
<div class="row">
<aside class="span4">
<section>
<%= render 'shared/user_info' %>
</section>
<section>
<%= render 'shared/micropost_form' %>
</section>
</aside>
</div>
<% else %>
<div class="center hero-unit">
<h1>Welcome to The Gentle Introduction Resource</h1>
<p>
This is the home page for the
The Gentle Introduction Resource
web app.
</p>
<%= link_to "Sign up now!", signup_path, class: "btn btn-large btn-primary" %>
</div>
<br/>
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>
But then when I include this code:
<div class="span8">
<h3>Micropost Feed</h3>
<%= render 'shared/feed' %>
</div>
it breaks.
Full home.html.erb:
<% if signed_in? %>
<div class="row">
<aside class="span4">
<section>
<%= render 'shared/user_info' %>
</section>
<section>
<%= render 'shared/micropost_form' %>
</section>
</aside>
<div class="span8">
<h3>Micropost Feed</h3>
<%= render 'shared/feed' %>
</div>
</div>
<% else %>
<div class="center hero-unit">
<h1>Welcome to The Gentle Introduction Resource</h1>
<p>
This is the home page for the
The Gentle Introduction Resource
web app.
</p>
<%= link_to "Sign up now!", signup_path, class: "btn btn-large btn-primary" %>
</div>
<br/>
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>
<% end %>
Here is my _feed.html.erb:
<% If #feed_items.any? %>
<ol class="microposts">
<%= render partial: 'shared/feed_item', collection: #feed_items %>
</ol>
<%= will_paginate #feed_items %>
<% end %>
And here is my _feed_item.html.erb
<li id="<%= feed_item.id %>">
<%= link_to gravatar_for(feed_item.user), feed_item.user %>
<span class="user">
<%= link_to feed_item.user.name, feed_item.user %>
</span>
<span class="content"><%= feed_item.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(feed_item.created_at) %> ago.
</span>
<% if current_user?(feed_item.user) %>
<%= link_to "delete", feed_item, method: delete,
data: { confirm: "You sure?" },
title: feed_item.content %>
<% end %>
</li>
Sorry in advance for my markup, this is my first stack overflow question.
Oh and here is the error I'm getting when I attempt to load my local site:
SyntaxError in Static_pages#home
Showing /rails_projects/sample_appOct20_2013/app/views/shared/_feed.html.erb where line #7 raised:
/rails_projects/sample_appOct20_2013/app/views/shared/_feed.html.erb:7: syntax error, unexpected keyword_ensure, expecting $end
Extracted source (around line #7):
4: </ol>
5: <%= will_paginate #feed_items %>
6: <% end %>
Trace of template inclusion: app/views/shared/_feed.html.erb, app/views/static_pages/home.html.erb
I think its the capital If
should be:
<% if #feed_items.any? %>
<ol class="microposts">
<%= render partial: 'shared/feed_item', collection: #feed_items %>
</ol>
<%= will_paginate #feed_items %>
<% end %>
Since this is the case, it thinks that the <% end %> tag is not needed. It really is needed but 'If' (capitalized) is not the same as 'if'(lowercase).