简体   繁体   English

无模型形式表

[英]No-Model Formtastic Form

I am looking to reproduce the following with Formtastic : 我希望用Formtastic重现以下内容

<% form_tag '/search', :method => 'get' do %>
  <%= text_field_tag :q, params[:q] %>
<% end %>

So far I have: 到目前为止,我有:

<% semantic_form_for :search, :html => { :method => :get } do |form| %>
  <% form.inputs do %>
    <%= form.input :q %>
  <% end %>
<% end %>

However, this requires access to the parameter hash using: 但是,这需要使用以下方法访问参数哈希:

params[:search][:q]

Instead of my required: 而不是我的要求:

params[:q]

I'd like to use Formtastic for all forms in the application I am working on, and so far I have only had problems with this one. 我想在我正在处理的应用程序中使用Formtastic用于所有表单,到目前为止我只遇到过这个问题。 Any ideas? 有任何想法吗?

<%= form.input :q, :input_html => { :name => 'q' } %>

Formtastic's semantic_form_for is wrapped around Rails' form_for, which only allows "model" forms like the one you're describing. Formtastic的semantic_form_for包含在Rails的form_for中,它只允许“模型”形式,就像你描述的那样。 I'm pretty sure you mean "desired" rather than "required", because it's pretty easy to access params[:search][:q] or duplicate the value to params[:q] yourself. 我很确定你的意思是“期望的”而不是“必需的”,因为很容易访问params [:search] [:q]或者自己将值复制到params [:q]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM