how do i get the comment id


PoVa

I'm developing a simple Blogger app and I'm trying to add commenting functionality to it. I'm trying to add delete/edit functionality to comments, but I don't know how to get the id of the comment I want to edit. This is what the html code looks like:

  <div class = "comment">
    <p class = "author">Comment by <%= comment.author_name %>
      <span class="creationTime"> <%= distance_of_time_in_words(comment.created_at, Time.now) %> ago</span>
    </p>
    <p class="text"><%= comment.body %></p>
    <div class = "Button">
      <%= link_to "Edit this comment", edit_article_comment_path(@comment.article_id, @comment.id) %>
    </div>
  </div>

Article controller display action:

def show
    @article = Article.find(params[:id])
    @comment = Comment.new
    @comment.article_id = @article.id
end

route:

    article_comments GET    /articles/:article_id/comments(.:format)          comments#index
                     POST   /articles/:article_id/comments(.:format)          comments#create
 new_article_comment GET    /articles/:article_id/comments/new(.:format)      comments#new
edit_article_comment GET    /articles/:article_id/comments/:id/edit(.:format) comments#edit
     article_comment GET    /articles/:article_id/comments/:id(.:format)      comments#show
                     PATCH  /articles/:article_id/comments/:id(.:format)      comments#update
                     PUT    /articles/:article_id/comments/:id(.:format)      comments#update
                     DELETE /articles/:article_id/comments/:id(.:format)      comments#destroy
            articles GET    /articles(.:format)                               articles#index
                     POST   /articles(.:format)                               articles#create
         new_article GET    /articles/new(.:format)                           articles#new
        edit_article GET    /articles/:id/edit(.:format)                      articles#edit
             article GET    /articles/:id(.:format)                           articles#show
                     PATCH  /articles/:id(.:format)                           articles#update
                     PUT    /articles/:id(.:format)                           articles#update
                     DELETE /articles/:id(.:format)                           articles#destroy
                root GET    /                                                 articles#index

error i get:

No route matches {:action=>"edit", :article_id=>"1", :controller=>"comments", :id=>nil} missing required keys: [:id]

Sorry if I'm asking a stupid question, I'm new to this

Saha Prosenjit

Your article controller should look like this:

def show
  @article = Article.find(params[:id])
  @comments = @article.comments
end

Your view should look like this:

<% @comments.each do |comment| %>
  <div class = "comment">
    <p class = "author">Comment by <%= comment.author_name %>
      <span class="creationTime"> 
        <%= distance_of_time_in_words(comment.created_at, Time.now) %> ago
      </span>
    </p>
    <p class="text"><%= comment.body %></p>
    <div class = "Button">
      <%= link_to "Edit this comment", edit_article_comment_path(@article, comment) %>
    </div>
  </div>
<% end %> 

Also add the association has_manyto the Article model.

has_many :comments

Hope you have been added article_idto the comment form

Related


how do i get the comment id

PoVa I'm developing a simple Blogger app and I'm trying to add commenting functionality to it. I'm trying to add delete/edit functionality to comments, but I don't know how to get the id of the comment I want to edit. This is what the html code looks like: <

how do i get the comment id

PoVa I'm developing a simple Blogger app and I'm trying to add commenting functionality to it. I'm trying to add delete/edit functionality to comments, but I don't know how to get the id of the comment I want to edit. This is what the html code looks like: <

how do i get guild.id

vijat6856 I'm putting together a class with proper permissions, but I need some kind of guild ID. How can i get the guild server id by the user who wrote this command if (message.channel.type === "text" && message.guild && message.guild.ownerID == message.

How do i get the facebook post id?

a7madx7 How to extract post id after posting post using Facebook method Post() or PostTaskAsync() ? I use JSON.Netsomething like this var postObject = await fb.PostTaskAsync("/me/feed", postArgs); dynamic result = JsonConvert.DeserializeObject((

how do i get guild.id

vijat6856 I'm putting together a class with proper permissions, but I need some kind of guild ID. How can i get the guild server id by the user who wrote this command if (message.channel.type === "text" && message.guild && message.guild.ownerID == message.

how do i get the contact id

Christian Mandel I have a problem getting the contact id from the address book. My .m file: -(IBAction)test:(id)sender { ABPeoplePickerNavigationController* picker = [[ABPeoplePickerNavigationController alloc] init]; picker.peoplePickerDelegate = self;

how do i get guild.id

vijat6856 I'm putting together a class with proper permissions, but I need some kind of guild ID. How can i get the guild server id by the user who wrote this command if (message.channel.type === "text" && message.guild && message.guild.ownerID == message.

how do i get guild.id

vijat6856 I'm putting together a class with proper permissions, but I need some kind of guild ID. How can i get the guild server id by the user who wrote this command if (message.channel.type === "text" && message.guild && message.guild.ownerID == message.

how do i get guild.id

vijat6856 I'm putting together a class with proper permissions, but I need some kind of guild ID. How can i get the guild server id by the user who wrote this command if (message.channel.type === "text" && message.guild && message.guild.ownerID == message.

how do i get guild.id

vijat6856 I'm putting together a class with proper permissions, but I need some kind of guild ID. How can i get the guild server id by the user who wrote this command if (message.channel.type === "text" && message.guild && message.guild.ownerID == message.

how do i get guild.id

vijat6856 I'm putting together a class with proper permissions, but I need some kind of guild ID. How can i get the guild server id by the user who wrote this command if (message.channel.type === "text" && message.guild && message.guild.ownerID == message.

How do i get the facebook post id?

a7madx7 How to extract post id after posting post using Facebook method Post() or PostTaskAsync() ? I use JSON.Netsomething like this var postObject = await fb.PostTaskAsync("/me/feed", postArgs); dynamic result = JsonConvert.DeserializeObject((

How do I get the ID after the get call?

Oliver Lowman I want to locate the id via gettng, but I seem to only get the whole data, if I console log it I see the id and so on, but I don't know how to just print the id in the console log Here is a sample code: fetch('http://localhost:5000/get/' + f) .th

How do I get the customer ID if I have a Stripe token?

Stefanos Ioanu My app uses design to create new user and integrate it with Stripe. When a new customer is created, I get (in response) the token (ie the card's token). Is there a way to use that token to retrieve the customer's ID? I have a related question sh

How do I get the member's ID from their tag inconsistency?

hisup212: How can I search for example#0000 in a trade association's member list and get its ID using discord.js? Aplet123: If the user is cached, you can simply do: bot.users.cache.find(v => v.tag == "example#0000") However, if not cached, you can search for

How do I get the client ID for a new Google project?

let me think In my Google Cloud Platform dashboard, a new project was created. https://console.cloud.google.com/home/dashboard?project=my-new-project Where can I get my app's client ID and password? let me think On the platform dashboard console, there is a me

How do I get the process id that Python emits a signal from?

Ivan Kolesnikov Check out the following Python code: def Handler(signum, frame): #do something signal.signal(signal.SIGCHLD, Handler) Is there a way to get the process ID from which signal? Or is there another way to get the process ID of the source of th

How do I get the developer ID for the Google Custom Search API?

Eric Shelhamer I have a GAE application so I chose: public access API Browser (or should I choose server) *.mysite.appspot.com/*, *.googleapis.com/*, http://localhost:8080/* I make the api call in the following way: from lib.googleapiclient.discovery import b

How do I get to the document's _id in the parent data context?

Yeats It seems like an on and off case Template.parentData()for , but so far I've never managed to get that bad boy to work. What I want is an event that updates the document based on the button clicked, but the button itself relies on an array deeper in the d

How do I get the entity ID to call using the LUIS API?

Demon Golem There are many entity-based GET methods in the LUIS API, which require passing the entity's GUID (ie entityId). Let's take the example of deleting an entity with url https://[location].api.cognitive.microsoft.com/luis/api/v2.0/apps/{appId}/versions

How do I get the client ID for a new Google project?

let me think In my Google Cloud Platform dashboard, a new project was created. https://console.cloud.google.com/home/dashboard?project=my-new-project Where can I get my app's client ID and password? let me think On the platform dashboard console, there is a me

How do I get the recording ID from a Twilio recorded call?

Sathorn My twilio code is: const express = require('express'); const VoiceResponse = require('twilio').twiml.VoiceResponse; const app = express(); const PORT = process.env.PORT || 3000; app.get('/health', (req, res) => { res.send('ok') }) // Returns TwiML

How do I get the matching id for every record?

Tommaso Thea Cioni My table is called platform_statuses, here is its schema: CREATE TABLE platform_statuses ( id SERIAL, account INTEGER REFERENCES users (id), time TIMESTAMP DEFAULT NOW(), value_in_cents INTEGER NOT NULL, status INTEGER NO

How do I get the exact same audience size for the target id?

Iglis I have a graph facebook url like this https://graph.facebook.com/v8.0/act_ad_account_id/targetingsuggestions?targeting_list=[{'type':'interests','id':123456}]&access_token=my_access_token But this url doesn't respond exactly to the target id information

How do I get MsalGuard to use my client ID?

Erica I'm trying to setup my Angular app to use @azure/msal-angular. I have set up MsalModule like this: import { NgModule } from "@angular/core"; import { MsalModule, MsalInterceptor } from "@azure/msal-angular"; import { HTTP_INTERCEPTORS } from "@angular/co