【发布时间】:2013-08-25 08:17:27
【问题描述】:
我正在寻找如何在没有空格的情况下保存我的输入。
我通过
收集表单上的输入<%= f.input :name %>
并将其也用于链接
localhost:3000/users/:name
问题是,如果有人在他的名字中使用空格,则链接会变得很丑陋,带有 % 符号等。
如何在没有空格的情况下存储输入?
例如
输入是:Hey im John
另存为:HeyimJohn
我的模特:
class Show < ActiveRecord::Base
belongs_to :user
validates :name, :presence => true, :uniqueness => true
# Show Cover
has_attached_file :cover, styles: { show_cover: "870x150#"}
validates_attachment :cover,
content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png'] },
size: { less_than: 5.megabytes }
def to_param
name
end
end
【问题讨论】:
标签: ruby-on-rails validation input ruby-on-rails-4