我是 ruby 新手,在实现以 haml 语法进行搜索的视图时遇到了麻烦。
这是我的搜索控制器代码,效果很好
应用程序/控制器/搜索
def search(text)
@patients = @client.submit_search({ query: text, page: 1, page_size: 30 })
end
这是我在 /config 中的路线
match 'patients/index' => 'search/patients#index', via: :get
这是我的观点,其中包含以下表格:
//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
基本上,当我输入一些文本并点击提交时,我想在上面的 html 表格片段中显示患者姓名、患者年龄等。如果结果集为空,我不想显示 html 表格。但我不确定如何以haml格式实现它。