我遇到与我的html表单绑定ruby表单的问题。我绑定但形式没有显示和隐藏css样式。我正在使用轨道4.2.3。我已经使用过bootstrap gem。
<%= form_tag users_admin_path , :method=> :post do %>
<%= label_tag :factory_name%>
<%= text_field_tag :factory_name%>
<%= label_tag :email%>
<%= text_field_tag :email %>
<%= label_tag :password %>
<%= password_field_tag :password %>
<%= submit_tag "Sign in", class: "btn btn-large btn-primary" %>
<% end %>
这是我的html表单代码。
form class="form-horizontal">
<div class="col-md-6 col-md-offset-2 remove-margin">
<div class="form-group">
<label class="col-sm-3 control-label">User name</label>
<div class="col-sm-9">
<input type="text" class="form-control" placeholder="">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Email</label>
<div class="col-sm-9">
<input type="email" class="form-control" placeholder="">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Password</label>
<div class="col-sm-9">
<input type="password" class="form-control" placeholder="">
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"> </label>
<div class="col-sm-9">
<div class="btm-btn text-center">
<button type="submit" class="btn-type">Create</button>
</div>
</div>
</div>
</div>
</form>
答案 0 :(得分:0)
我解决了
<%= form_for @User, html: { :class => "form-horizontal"} do |f|%>
<div class="col-md-6 col-md-offset-2 remove-margin">
<div class="form-group">
<!-- <label class="col-sm-3 control-label">User name</label>-->
<%= f.label :user_name ,:class => "col-sm-3 control-label"%>
<div class="col-sm-9">
<!--<input type="text" class="form-control" placeholder="">-->
<%= f.text_field :user_name, :required => true, :class =>"form-control" %>
</div>
</div>
<div class="form-group">
<!--<label class="col-sm-3 control-label">Email</label>-->
<%= f.label :email,:class => "col-sm-3 control-label"%>
<div class="col-sm-9">
<!--<input type="email" class="form-control" placeholder="">-->
<%= f.email_field :email, :required => true, :class =>"form-control" %>
</div>
</div>
<div class="form-group">
<!-- <label class="col-sm-3 control-label">Password</label>-->
<%= f.label :password,:class => "col-sm-3 control-label"%>
<div class="col-sm-9">
<!--<input type="password" class="form-control" placeholder="">-->
<%= f.password_field :password, :required => true, :class =>"form-control" %>
</div>
</div>
<% end %>
<div class="form-group">
<!-- <label class="col-sm-3 control-label"> </label>-->
<div class="col-sm-9">
<div class="btm-btn text-center">
<!--<button type="submit" class="btn-type">Create</button>-->
<%= f.submit class: "btn btn-large btn-primary" %>
</div>
</div>
</div>
<% end %>
<!--</form>-->
</div>
</div>