Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8939009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:44:51+00:00 2026-06-15T10:44:51+00:00

I’m creating a simple inventory app, there is a view that lists ‘items’. It

  • 0

I’m creating a simple inventory app, there is a view that lists ‘items’. It has tables with these rows:

<tr>
<td><%= item.title %></td>
<td><%= item.desc %></td>
<td><%= item.value %></td>
<td><%= item.room.name %></td>
<td><%= item.user.username %></td>
<td>
  <%= link_to 'View', item %>
  <%= link_to 'Edit', edit_item_path(item) %>
  <%= link_to 'Delete', item, method: :delete, data: { confirm: 'Are you sure?' } %>
  <%= link_to 'Add Comment', !?????! %>
</td>
/tr>

I have a linked model for ‘comments’ set up but don’t know how to pass the 'item_id' to it when creating a new one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:44:52+00:00Added an answer on June 15, 2026 at 10:44 am

    The URL helpers actually accept the object to make a route for an association. Meaning, assuming you have a nested route for comments within items,

    resources :items do
      resources :comments
    end
    

    you can link_to the new_item_comments_path(item).

    The method new_item_comments_path(item) makes a string URL based on the new_item_comments route, which you feed to link_to to make an HTML <a> tag.

    To be clearer, in your view you would have:

      <%= link_to 'View', item %>
      <%= link_to 'Edit', edit_item_path(item) %>
      <%= link_to 'Delete', item, method: :delete, data: { confirm: 'Are you sure?' } %>
      <%= link_to 'Add Comment', new_item_comments_path(item) #-> (instead of ???) %>
    

    In this case, the item you are passing is the reference to your current item, which allows the URL helper to make a URL for it from the route.

    The Rails guide for routing should be a useful read for you.

    Now that’s assuming your Comment controller assigns the right stuff at the right place. You seemed to have figured that out, but I’ll explain for the sake of clarity (and future visitors)

    class CommentsController < ApplicationController
      # GET /item/:item_id/comments/new
      def new
        @comment = Comment.new
    
        @item = Item.find(params[:item_id])
        @comment.item = @item
        # render
      end
    
      # POST /item/:item_id/comments
      def create
        @comment = Comment.new(params[:comment])
    
        @item = Item.find(params[:item_id])
        @comment.item = @item
    
        # if @comment.save blah
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.