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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:31:22+00:00 2026-06-17T22:31:22+00:00

I’m trying to save Ransack searches to the database. I believe I should be

  • 0

I’m trying to save Ransack searches to the database. I believe I should be able to just store the params[:q] value, then append that to the search URL when I want to recall the search. I don’t know how to save the params[:q] value, though.

The URL that Ransack creates is something like this:

http://site.com/search?utf8=%E2%9C%93&q%5Bone%5D=something&q%5Btwo%5D=&q%5Bthree%5D=&q%5Blow_number%5D=0&q%5Bhigh_number%5D=300000&q%5Bfour%5D=&commit=Search

My route to the action that will save the search is:

match 'users/:id/saved_search_add' => 'users#saved_search_add', :as => :saved_search_add

If I use this code in the view:

<%= link_to('Save Search', saved_search_add_path(current_user, :q => params[:q])) %>

With this code in the controller:

  def saved_search_add
    @saved_search = Search.create(:query => params[:q].to_hash, :user_id => @user.id)

    respond_to do |format|
      if @saved_search.save
        format.html { redirect_to(:back) }
      else
        format.html { redirect_to(:back) }
      end
    end
  end

Then the data stored is:

--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
one: ''
two: ''
three: ''
low_number: '0'
high_number: '300000'
four: ''

So, I need to somehow format the data as it’s going into the database (and perhaps also as it’s coming out?)… I’ve read something about serializing it, but I haven’t had much luck getting that to work.

How can I get params[:q] into my database, to be used later to recreate the full search URL?

  • 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-17T22:31:24+00:00Added an answer on June 17, 2026 at 10:31 pm

    I ended up just using request.fullpath instead of params[:q].

    The code that saves the query to the database is in the Users Controller:

    def saved_search_add
      @saved_search = Search.create(:query => params[:q], :user_id => current_user.id)
    
      respond_to do |format|
        if @saved_search.save
          format.html { redirect_to(:back) }
        else
          format.html { redirect_to(:back) }
        end
      end
    end
    

    The code I use in my View to send the search query to the Users Controller is:

    <%= link_to('Save Search', saved_search_add_path(current_user, :q => request.fullpath)) %>
    

    The query value is stored in the database as:

    /search?utf8=%E2%9C%93&q%5Bone%5D=something&q%5Btwo%5D=&q%5Bthree%5D=&q%5Blow_number%5D=0&q%5Bhigh_number%5D=300000&q%5Bfour%5D=&commit=Search
    

    I create the link to that saved search in the View with:

    <%= link_to "Saved Search", search.query %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.