这是我的schema.rb
create_table "users", force: true do |t|
t.string "name", limit: 6
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
end
Run Code Online (Sandbox Code Playgroud)
我为列"name"设置了字符串限制.
然后,在控制台中:
user = User.new(name:"1234567890",email:"username@gmail.com")
user.save!
Run Code Online (Sandbox Code Playgroud)
它引发了错误:
ActiveRecord::StatementInvalid: Mysql2::Error: Data too long for column 'name' at row 1: INSERT INTO `users` (`created_at`, `email`, `name`, `updated_at`) VALUES ('2014-06-19 15:08:15', 'username@gmail.com', '1234567890', '2014-06-19 15:08:15')
Run Code Online (Sandbox Code Playgroud)
但是,当我切换到导轨3.
我发现它自动截断了字符串" 1234567890 ",并将" 123456 "插入数据库而没有错误.
有什么关于这个已被删除在rails 4?
我应该自己在模型中添加一些截断函数吗?谢谢!
最近,我学习了开发rails应用程序.现在,我有一个问题.我想换成生产模式.但我不想手动在开发数据库中复制我的数据.我该怎么办?我使用mysql和Mac os和rails 3 beta.韩国社交协会.
我正在将项目从rails 3升级到rails 4.当我切换到rails 4时,我在日志中遇到了这个错误.但是我没有把这个方法传递给任何论据.
ActionView::Template::Error (wrong number of arguments (1 for 0)):
1: <div id="titles_list">
2:
3: <div id="admin_title_select_group">
4: <% table_group = select_table_group %>
5: <%= select_tag 'selected_group', options_for_select(table_group, by_default_selected_group) %>
6: </div>
7:
app/helpers/admin/titles_helper.rb:14:in `select_table_group'
app/views/admin/titles/index.html.erb:4:in `_app_views_admin_titles_index_html_erb__3791160006166460542_70179046974220'
lib/metal/search_store.rb:17:in `call'
Run Code Online (Sandbox Code Playgroud)
index.html.erb
<div id="titles_list">
<div id="admin_title_select_group">
<% table_group = select_table_group %>
<%= select_tag 'selected_group', options_for_select(table_group, by_default_selected_group) %>
</div>
...
Run Code Online (Sandbox Code Playgroud)
这是我的帮手方法:
module Admin::TitlesHelper
def select_table_group
g = [[I18n.t('admin.tpgn.select_group'),0]]
g += TitleProviderGroupName.all(:order => :name).collect{|t| [ t.name, t.id ]}
end
def by_default_selected_group
if …Run Code Online (Sandbox Code Playgroud)