我已经开始使用simple_form
的新应用,而且我的表单没有样式。
的Gemfile:
source 'https://rubygems.org'
# BACK
gem 'rails', '4.2.7.1'
gem 'pg', '~> 0.15'
# FRONT
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'uglifier', '>= 1.3.0'
gem 'jbuilder', '~> 2.0'
gem 'simple_form'
gem 'slim'
gem 'bootstrap', '~> 4.1.1'
gem 'sprockets-rails', '>=2.3.2'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'rspec-rails', '~> 3.7'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
gem 'rubocop'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
我的app/assets/stylesheets/application.rb
:
@import "bootstrap";
表格代码:
.row
.offset-md-3.col-md-6
= simple_form_for :user, url: sessions_path do |f|
= f.text_field :username
= f.password_field :password
= f.submit 'Войти'
它会生成
<form novalidate="novalidate" class="simple_form user" action="/sessions" accept-charset="UTF-8" method="post">
<input name="utf8" type="hidden" value="✓">
<input type="hidden" name="authenticity_token" value="...">
<input type="text" name="user[username]" id="user_username">
<input type="password" name="user[password]" id="user_password">
<input type="submit" name="commit" value="Войти">
</form>
看起来像这样:
我可以看到,它至少不会在每个输入周围生成<div class='form-group'>
等。
我跑了rails generate simple_form:install --bootstrap
。并且可以提供所需的所有信息。
有什么意义呢?
答案 0 :(得分:0)