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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:35:55+00:00 2026-06-18T11:35:55+00:00

I am new to ruby and am having trouble implementing the view for search

  • 0

I am new to ruby and am having trouble implementing the view for search in haml syntax.

Here is my controller code for search which works fine

app/controllers/search

def search(text)
      @patients = @client.submit_search({ query: text, page: 1, page_size: 30 })
 end

This is my route in /config

match 'patients/index' => 'search/patients#index', via: :get

This is my views where in contains the form:

//Search Form
%h2 Patient Search
.search-form-elements
  %form{ :action => "", :method => "get"}

    %label{:for => "name"} First Name:
    %input{:type => "text", :name =>"first_name"}

    %label{:for => "name"} Last Name:
    %input{:type => "text", :name =>"last_name"}


    %label{:for => "name"}
    %input{:type => "submit", :value => "Search", :class => "button"}

  %table.table.table-bordered.table-condensed
    %tr
      %th
        Patient Name
      %th
        Id#
      %th
        Age
      %th
        Gender

Basically when I type some text and hit submit I want to display patient.name,patient.age etc in the above html table fragment .I do not want to show the html table if the result set is empty. but I am not sure how to implement this in haml format.

  • 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-18T11:35:56+00:00Added an answer on June 18, 2026 at 11:35 am

    Here is how I would do that. I assume here that you have your list of patients on the index view.

    In your view :

    = form_tag patients_path, method: 'get' do
      = text_field_tag :search, params[:search]
      = submit_tag "Search", :name => nil
    
    - if @patients.present?
      %table.table.table-bordered.table-condensed
        %tr
          %th Patient Name
          %th Id
          %th Age
          %th Gender
    
        - @patients.each do |patient|
    
          %tr
            %td= patient.name
            %td= patient.id
            %td= patient.age
            %td= patient.gender
    

    In your Patient controller:

    def index
      @patients= Patient.search(params[:search])
    end
    

    And in your model:

    def self.search(search)
      key = "%#{search}%"
      if search
        where('first_name LIKE ? OR last_name LIKE ?', key, key)
      else
        all
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm brand new to ruby and rails and I'm having trouble creating a sign-out
Im new to ruby, wrote this code and works but i know is not
I'm having trouble with a regex in Ruby (on Rails). I'm relatively new to
Having trouble setting up a Rake Task. Here is the code: task :fetch_games =>
I'm very new to Rails (and Ruby), and am having trouble installing and using
I am new to Ruby and Rails and am having trouble getting a class
im really new to ruby and ROR and im having real trouble trying to
I am beginner in Ruby and having trouble understanding this code require_relative 'custom_page' module
Being new to Ruby, I'm having trouble explaining to myself the behavior around method
I'm new to Ruby, so I'm having some trouble understanding this weird exception problem

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.