我正在尝试验证电话号码是否为数字: -
这是我的user.rg
number_regex = /\d[0-9]\)*\z/
validates_format_of :phone, :with => number_regex, :message => "Only positive number without spaces are allowed"
Run Code Online (Sandbox Code Playgroud)
这是我的view.html.haml
%li
%strong=f.label :phone, "Phone Number"
=f.text_field :phone, :placeholder => "Your phone number"
Run Code Online (Sandbox Code Playgroud)
这是控制器
def edit_profile
@user = current_user
request.method.inspect
if request.method == "POST"
if @user.update_attributes(params[:user])
sign_in(@user, :bypass => true)
flash[:success] = "You have updated your profile successfully"
redirect_to dashboard_index_path
else
flash[:error] = "Profile could not be updated"
render :action => "edit_profile"
end
end
end
Run Code Online (Sandbox Code Playgroud)
当我第一次在文本字段中输入数字时,它会正确验证,但如果我输入正确的格式然后尝试输入错误的格式,它会跳过验证,我会收到一条flash消息,表明配置文件已成功更新,但是错误的值(带字母)不会保存.
这可能是什么问题?
我现在面对这个问题一段时间了,请仔细研究一下.
object.inspect给了我这个输出
<RawMaterial id: nil, name: "Jam Button 9 mm Antique Silver", rate: 1.0, raw_material_wastage: 0.0, total_raw_material: 8.0, slug: nil, costing_id: nil, created_at: nil, updated_at: nil, inventory_item_id: 758, costing_wastage: 0.0, pick_from_order_sheet: false>
Run Code Online (Sandbox Code Playgroud)
raise object.to_yaml给出了这个输出
-- !ruby/object:RawMaterial
raw_attributes:
costing_id:
id:
name: Jam Button 9 mm Antique Silver
rate: '1'
raw_material_wastage: '0'
total_raw_material: '8'
slug:
created_at:
updated_at:
inventory_item_id: '758'
costing_wastage: '0'
pick_from_order_sheet: f
attributes: !ruby/object:ActiveRecord::AttributeSet
attributes: !ruby/object:ActiveRecord::LazyAttributeHash
types:
id: &3 !ruby/object:ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer
precision:
scale:
limit:
range: !ruby/range
begin: -2147483648
end: 2147483648
excl: true …Run Code Online (Sandbox Code Playgroud) 我正在循环遍历各国,按字母顺序获取国家/地区列表.所需的显示形式如下图所示:

但是我现在正是这样的

我正在使用无序列表来实现所需的结果.
这是代码: -
视图中的代码: -
<% User.find(:all, :order => "name").group_by(&:initial).each do |initial, users| %>
<table>
<ul>
<li><%= content_tag(:h3, initial)%> </li>
</ul>
<% users.each do |user|%>
<ul>
<li> <%= link_to(user.name, user)%> </li>
</ul>
<% end %>
</table>
<% end %>
Run Code Online (Sandbox Code Playgroud)
CSS: -
ul {
list-style: none;
}
Run Code Online (Sandbox Code Playgroud)
有人可以指导我吗?
谢谢