[英]How do I create a category by clicking on an image on ruby on rails
I want to create search by clicking on a category. 我想通过单击类别来创建搜索。 I have this code which works
我有这个代码有效
<%= search_form_for @q , id: 'myform' , :html => {:class => "form-inline"} do |f| %>
<%= f.text_field :category_id_eq, value: 1, type: 'hidden' %>
<%= content_tag(:button, "Foo", :type=>:submit) do %>
<div class="col-sm-3 ">
Image goes here
</div>
<% end %> <% end %>
but the button is not the image I want. 但是按钮不是我想要的图像。 It is just a big ugly button.
这只是一个很大的丑陋按钮。 Therefore I want to do something like this.
因此,我想做这样的事情。 Bt it does not work.
但它不起作用。
<%= search_form_for @q , id: 'myform' , :html => {:class => "form-inline"} do |f| %>
<%= f.text_field :category_id_eq, value: 1, type: 'hidden' %>
<div class="col-sm-3 " onclick="document.myform.submit()">
Image goes here
</div>
<% end %><% end %>
My question exactly is, how do I turn a div into a submit button? 我的问题恰恰是,如何将div变成“提交”按钮? or how can I search by clicking on an image.
或者如何通过单击图像进行搜索。
Thanks. 谢谢。
This is the way I solved the problem. 这就是我解决问题的方法。 The Use the first example which was correct and I simply style it with css.
使用第一个正确的示例,我简单地使用css对其进行样式设置。
<%= search_form_for @q , id: 'myform' , :html => {:class => "form-inline"} do |f| %>
<%= f.text_field :category_id_eq, value: 1, type: 'hidden' %>
<%= content_tag(:button, "Foo", :type=>:submit, class: 'category_button' ) do %>
<div class="col-sm-3 ">
Image goes here
</div>
<% end %>
<% end %>
CSS I reset Code: 我重置的CSS代码:
.category_button{
background: none repeat scroll 0 0 transparent;
margin: 0;
padding: 0;
border: none;
display: inline-block;
height: 0px;
width: 0px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.