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 9134211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:37:11+00:00 2026-06-17T08:37:11+00:00

In my application I have List objects and Problem objects, Lists are made up

  • 0

In my application I have List objects and Problem objects, Lists are made up of Problems and problems can belong to many lists. I am using HABTM on both classes and I’ve created their join table like so:

class AddTableListsProblems < ActiveRecord::Migration
  def up
    create_table :lists_problems, :id => false do |t|
    t.references :list
    t.references :problem
    t.timestamps
end
  end

  def down
    drop_table :lists_problems
  end
end

Now, within the show view of my list I intend to display a list of all Problems and provide a “link_to” to add this problem to the current List being shown but I can’t seem to figure out how to. I’m new to RoR so the solution is probably simple though I cant seem to get around it.

This is the code i currently have.

    <% @problems.each do |problem| %>
      <%= render problem %>
          | <%= link_to "Add to current list", <How do I access the List.problems method to add the problem and create a relation?> %>
    <% end %>

Thanks in advance for your help.

  • 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-17T08:37:12+00:00Added an answer on June 17, 2026 at 8:37 am

    Let’s say you have a ListController. You’ll add an add_problem action to it.

    def add_problem
      list    = List.find(params[:id])
      problem = Problem.find(params[:problem_id])
    
      list.problems << problem # This appends and saves the problem you selected
    
      redirect_to some_route # change this to whatever route you like
    end
    

    And you’ll need to create a new route for this. Assuming you’re using resourceful routes you might have something like

    resources :list do
      member do
        put "add-problem/:problem_id", action: :add_problem, as: :add_problem
      end
    end
    

    This will generate the following route

    add_problem_list PUT    /list/:id/add-problem/:problem_id(.:format)    list#add_problem
    

    In your view you’ll change your link_to

    <% @problems.each do |problem| %>
      <%= render problem %>
          | <%= link_to "Add to current list", add_problem_list_path(list: @list, problem_id: problem.id), method: :put %>
    <% end %>
    

    Note This is just an example; you’d want to do authorization/validation/etc… in the add_problem method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array list of objects in my application. private static ArrayList<Player> userList=new
I am creating an application that will have a list of items that can
I have a swing application which stores a list of objects. When the users
I have this problem with late binding: I am creating a grocery list application.
I have made one application which can parse the given xml file independent of
In my MVC3 application i have a dropdown list. In there i have to
Imagine the typical type of application where you have a list of items with
In my application, I have list view. Selecting another item in it, triggers an
I have a List in the main application and I am trying to access
In my application I have to send a List<MenuItem> to my shell extension in

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.