如何将 Bootstrap 类添加到 Ransack form_for [已关闭]

问题描述 投票:0回答:1

在views/articles/index.html.erb中:

<%= search_form_for  @q  do |f| %>
  <%= f.label :title %>
  <%= f.search_field :title_or_body_cont_any %>
  <%= f.submit %>
<% end %>

我尝试添加 class="btn btn-primary" 来提交:

<%= f.submit,class="btn btn-primary"  %>

但我收到错误。如何将 Bootstrap 类加入到 form_for 字段?

全视图:

<div class="container">
  <%= search_form_for  @q  do |f| %>
    <%= f.search_field :title_or_body_cont_any %>
    <%= f.submit  %>
  <% end %>
  <br/>
  <% @articles.each do |article|%>
  <div class="border border-success p-2 border-opacity-25 rounded">
    <p>
        <%= link_to article.title, article_path(article), style: 'color:#d63e2d; font-size: 30px; ' %> 
        
    </p>

    <p>
        <%= markdown article.body%>
    </p>

  </div>
  <br/>
  <%end%>
</div>

完整错误跟踪______________________________________:

app/views/articles/index.html.erb:4: syntax error, unexpected ')', expecting '.' or &. or :: or '['
app/views/articles/index.html.erb:5: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:23: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:4: syntax error, unexpected ')', expecting '.' or &. or :: or '['
app/views/articles/index.html.erb:5: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:23: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:4: syntax error, unexpected ')', expecting '.' or &. or :: or '['
app/views/articles/index.html.erb:5: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:23: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:4: syntax error, unexpected ')', expecting '.' or &. or :: or '['
app/views/articles/index.html.erb:5: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:23: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:4: syntax error, unexpected ')', expecting '.' or &. or :: or '['
app/views/articles/index.html.erb:5: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:23: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:4: syntax error, unexpected ')', expecting '.' or &. or :: or '['
app/views/articles/index.html.erb:5: syntax error, unexpected `end', expecting ')'
app/views/articles/index.html.erb:23: syntax error, unexpected `end', expecting ')' 
ruby-on-rails bootstrap-5 ransack
1个回答
0
投票

显然,

search_form_for
是通常的形式包装器

因此,这是通常的提交,并且作为选项通过课程就足够了:

<%= f.submit, class: "btn btn-primary"  %>
© www.soinside.com 2019 - 2024. All rights reserved.