Ask A Question

Notifications

You’re not receiving notifications from this thread.

Add a coment in a post ( how can I do)?

Federico Calarco asked in General

I'm coding my personal website , I have a backoffice where I can write blog_post ( title , content , category and date ).
I would like to make user comment my blog post without being logged in .
This is the code in /layouts/home.html.erb.

<section class="blog id col-sm-12">




<h1 class="col-sm-10 col-sm-offset-2 text-left">Blog post</h1>



      <div class="col-sm-2"></div>

                    <% @blog_posts.each do |blog_post| %>

                      <div class="col-sm-5  blog_post ">

                                <div class="col-sm-12 post">

                        <h3 class="col-sm-12 text-left"><%= blog_post.title.capitalize  %></h3>

                            <span class="col-sm-1" style="background-color:white;"></span>

                              <p class="col-sm-12 text-left content">"<%= blog_post.description.capitalize %>"</p>

                              <p class="col-sm-8 text-left"> <i class="fa fa-circle" style="color:#F0F4C3;"> <%= blog_post.category.capitalize %></i></p>

                              <p class="col-sm-4 text-right"> <%= blog_post.post_date  %> </p>

                              <p class="col-sm-12 text-left content">"<%= blog_post.comments.count %>"</p>

                              </div>


                <p class="col-sm-6  btn-default text-center post_button"><%= link_to 'Visualizza', blog_post %></p>

                <p class="col-sm-6 btn-default text-center post_button comment"><a href="#0">Commenta</a></p>


            </div>

<div class="col-sm-2"></div>

      <% end %>

<% if admin? %>

<%= link_to 'New Blog post', new_blog_post_path %>
<%= link_to 'Logout', destroy_admin_session_path, method: :delete %>

<% end %>



This is the section that comes out if an user click on "blog" , at the ond of if there is a button with "commenta", clicking it appears  a modal with 3 fields , name , email and comment. 

Comments belong to blog post and blog post has many comments obviously, I know I should set something in the controller but i really don't know what .
I had some suggestions but everybody told me how to make user add a comment in blog_post #show , but i would like to make them comment directly from the homepage.

Every advice is good :D 

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 78,890+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.