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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:42:02+00:00 2026-05-27T19:42:02+00:00

I have query to the db, where I ask for specific entries. This is

  • 0

I have query to the db, where I ask for specific entries. This is the controller:

  def index

    @contributions = Contribution.all
    @number1 = params[:number1]
    @number2 = params[:number2]
    @itemsok = Contribution.where("first_item_id = ?",@number1).where("first_item_grade = ?",@number2) 


    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @contributions }
    end

Ok and I have a form in the view wich allows me to pass data from the user input

<%= form_tag(contribution_path, :method => "get") do %>
  <%= label_tag(:number1, "First Item Id") %>
  <%= text_field_tag(:number1) %>
  <%= label_tag(:number1, "First Item Grade") %>
  <%= text_field_tag(:number2) %>
  <%= submit_tag("Do it!" , :remote => true) %>
<% end %>

That works perfectly, but now I want to render this function from the main page index (display_controller, display index.html.erb). I gave all the properties to the display_controller like this:

class DisplayController < ApplicationController
  def index
    @items = Item.all
    @contributions = Contribution.all
    @number1 = params[:number1]
    @number2 = params[:number2]
    @itemsok = Contribution.where("first_item_id = ?",@number1).where("first_item_grade = ?",@number2)
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @contributions }
    end
  end

end

And I have the same form in the display view that is in the contributions view….
Right now what It does is that it redirects me to the contributions part, what I want t achive is to render the results in the display view…

Any thoughts? Thank you very much.
Sorry for my terrible english.

#

I got it

Got it the answer was to change in view the form to selected action

<%= form_tag(contribution_path, :method => "get") do %>
  <%= label_tag(:number1, "First Item Id") %>
  <%= text_field_tag(:number1) %>
  <%= label_tag(:number1, "First Item Grade") %>
  <%= text_field_tag(:number2) %>
  <%= submit_tag("Do it!" , :remote => true) %>
<% end %>

Change it to

<%= form_tag(display_path, :method => "get") do %>
  <%= label_tag(:number1, "First Item Id") %>
  <%= text_field_tag(:number1) %>
  <%= label_tag(:number1, "First Item Grade") %>
  <%= text_field_tag(:number2) %>
  <%= submit_tag("Do it!" , :remote => true) %>
<% end %>

In my case this was not working at the beginning but now I figured that it was because I have my display_path as the root_path so I changed it to…

<%= form_tag(root_path, :method => "get") do %>
  <%= label_tag(:number1, "First Item Id") %>
  <%= text_field_tag(:number1) %>
  <%= label_tag(:number1, "First Item Grade") %>
  <%= text_field_tag(:number2) %>
  <%= submit_tag("Do it!" , :remote => true) %>
<% end %>

And now it works perfectly.

Can someone change this question to answered, I have like 21 of reputation and can’t answer my own question. Tanks.

  • 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-05-27T19:42:03+00:00Added an answer on May 27, 2026 at 7:42 pm

    For better code quelity you should avoid repititions of code and make reusable, move that formm to a common partial view and use :url =>{:action => 'my_action'} in the form tag then you can use it any controller index view. While form action it will take the default controller from which it will be rendered.

    share/_form.erb.html
    
    <%= form_tag(:url =>{:action => 'my_action'}, :method => "get") do %>
      <%= label_tag(:number1, "First Item Id") %>
      <%= text_field_tag(:number1) %>
      <%= label_tag(:number1, "First Item Grade") %>
      <%= text_field_tag(:number2) %>
      <%= submit_tag("Do it!" , :remote => true) %>
    <% end %>
    

    and in controller respective index view

     index.erb.html
    
     <%= render :partial 'share/form' %>
    

    you can even declare variables for action and controller in your index method like

    def index
     // do something
      @action = 'new_action'
      @controller = 'new_controller'
      // do some more thing
    end
    

    and then in form

    :url =>{:controller => @controller, :action => @action}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a feeling I am completely borking this MySQL query but I'll ask
I have this query that's running too slow. I'm not sure what all info
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
sorry, i dont like to ask such instance specific questions but this is driving
today i need your help to get an specific sql select query. i have
I have this query to count views in a table, by date. It obviously
I have a sql-query where I ask for some dates. "SELECT DISTINCT date FROM
All, I have my application setup so that i can use a specific username

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.