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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:03:18+00:00 2026-06-07T16:03:18+00:00

I’m trying to pass the value of a element to a rails controller! Currently,

  • 0

I’m trying to pass the value of a element to a rails controller!

Currently, I have something like this:

<td id="dbname"><%= link_to db, :action => :show %></td>

This represents a row in an html table, which contains a string value, e.g. “development”.

When the user clicks on the “development” link, the <%= link_to … %> grabs the value from the current clicked and passes that to a rails controller action, in this case the show action.

How can this be achieved!?

UPDATE – generating links:

<% @dbs.each do |db| %>
<tr>
    <td id="dbname"><%= link_to db, :action => :show %> </td>
</tr>

UPDATE 2:

this is my index controller:

conn = Mongo::Connection.new
@dbs = conn.database_names #this returns an array of strings (which are the names of the databases)

Now I want to be able to click on of these databases and then to pass the clicked text to the rails controller show action. I’m not sure how I would generate a custom resources path for these links… but I was contemplating of doing it using Ajax or something javascript related. Maybe get the text of clicked link using jQuery and then send an Ajax request to the rails controller with the text as a parameter!

  • 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-07T16:03:19+00:00Added an answer on June 7, 2026 at 4:03 pm

    I think that it’s a strange thing what you’re trying to do, but a solution could be to use javascript to append the id to the href of each link as a query string.

    If you could explain a little bit what you’re trying to achieve maybe we could find a better solution.

    Hope it helps!

    Edit:

    If you have a table of links I think that you should consider them as a resource and managing them the REST way.

    Your controller should have an index and show action and you should declare the links as a resource in the routes file (maybe link it’s a reserved word and you will have to use a different name, I’m not sure), the index action will fetch all the links and when you render them, you could specify the link for each one with something similar to “link_path(link.id)” (remember, you should have a show action defined) in the controller you will receive the link id so you could load it with a simple “find” and pass it to the view.

    I recommend you to always look for the REST way to solve a problem in ROR.

    Edit 2:

    Ok let’s see if this works for you:

    I suppose that you have a model that represent those links that you’re talkin about, for example:

    class DataBaseLinks < ActiveRecord:Base
    
    end
    

    This model with be backed up by a table in your database, if you have generated it the rails way, you will also have an id column that identify each database link.

    in your controller, let’s say DataBaseLinksController, you’ll have:

    class DataBaseLinksController < ApplicationController
    
      def index
        @dabatase_links = DataBaseLink.all
      end
    
      def show
        @database_link = DataBaseLink.find(params[:id])
      end
    
    end
    

    (I’ve avoided all the validations and checks).

    All you have to do in your index.html.erb is:

    <% @database_links.each do |database_link| %>
      <%= link_to database_link.name, database_link_path(database_link.id) %>
    <% end %>
    

    This will generate all the links with the correct path to the show action (maybe the route helper is a little bit different, but not so much).

    Notice also that you’ll have to add into your routes.rb the following line:

    resources :database_links, :only => [:index, :show]
    

    How do you see it?

    Edit 3:

    (I’ll delete all my edited answers when we find a correct one)

    Ok I’m going to suppose that you are not using something like mongoid so you don’t have active record similar objects.

    Have you tried this in your view:

    <% dbs.each do |dbs_name| %>
      <%= link_to dbs_name, :controller => "your_controller", :action => :show, :dbs_name => dbs_name %>
    <% end %> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am currently running into a problem where an element is coming back from
I am trying to loop through a bunch of documents I have to put

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.