我有一个简单的搜索表单,在rails 4应用程序,需要两个参数传递到能够显示相关数据。ActiveRecord :: StatementInvalid在显示控制器
我收到'Mysql2 ::错误:未知列'数据输入',但列确实存在。如果我代替'@search = Page.where(params[:one] && params[:two])
',则使用'@search = Page.all
'数据显示,但全部显示。
表
<%= form_tag(page_show_path, id: "search-form") do %>
<%= text_field_tag :one, params[:one], placeholder: "One" %>
<%= text_field_tag :two, params[:two], placeholder: "Two" %>
<%= submit_tag "Search", :name => nil %>
<% end %>
模型
def self.one(query)
where("one = ?", "%#{query}%")
end
def self.two(query)
where("two = ?", "%#{query}%")
end
控制器
def show
if (params[:one] && params[:two]).present?
@search = Page.where(params[:one] && params[:two])
else
redirect_to page_path, notice: "Not a valid combination"
end
end
什么是您的列名? –
一个和两个..... – DollarChills
尝试用'一个'来改变'one'。可能是这个问题是大小写敏感的。 –