小编smi*_*ike的帖子

RAILS 3.2&Devise:电子邮件确认文本字段?

我正在使用Rails 3.2和Devise.我想知道Devise是否提供了"电子邮件(地址)确认"字段,就像密码确认一样,用户输入密码字段,然后在网站发出确认电子邮件或处理注册登记之前输入密码确认字段.如果没有,我是否必须添加email_confirmation并验证用户模型(在rails g devise User之后)?

提前致谢

ruby-on-rails devise

5
推荐指数
2
解决办法
2710
查看次数

使用has_one和belongs_to的嵌套路由和form_for和模型

如何使用嵌套路由映射has_one模型以及如何在RESTful数据库之后为/localhost:3000/users/1/profile/new,html.erb添加form_for?

用户有一个个人资料.

楷模

class Profile < ActiveRecord::Base
  attr_accessible :name, :surname
  belongs_to :user
end

class User < ActiveRecord::Base
  attr_accessible :email, :email_confirmation, :password, :password_confirmation
  has_secure_password
  has_one :profile, dependent: :destroy
end

  resources :users do
    resources :profiles      (note: has_one profile)
    resources :progress_charts
    resources :calories_journals
  end
Run Code Online (Sandbox Code Playgroud)

意见/型材/ new.html.erb

<h1>About You</h1>
<div class="row">
  <div class="span6 offset3">
    <%= form_for(@profile) do |f| %>
    <%= render 'shared/error_messages' %>

      <%= f.label :name %>
      <%= f.text_field :name %>

      <%= f.label :surname %>
      <%= f.text_field :surname %>

      <%= f.submit "Create my account", …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails controllers form-for nested-resources ruby-on-rails-3

4
推荐指数
1
解决办法
2484
查看次数

如何使用 REGEX (Groovy) 选择单词“She”、“Shell”和 REGEX =“She”?

我是 REGEX 的新手,我试图只得到“She”和“Shell”这两个词,而不是这个程序(Groovy)的灰烬。我已经工作了一段时间。

saying = 'She wishes for Shells not ashes'
println saying
def pattern = ~/\bShe*\b/
def matcher = pattern.matcher(saying)
def count = matcher.getCount()
println "Matches = ${count}"
for (i in 0..<count) {
    print matcher[i] + " "
}
Run Code Online (Sandbox Code Playgroud)

输出:她想要的是贝壳而不是灰烬火柴 = 1 她

REGEX 不像 Windows CMD 那样工作,例如 dir W* 来列出以 W 开头的文件夹或文件。我做错了什么?

非常感谢您回答这个问题

regex groovy

3
推荐指数
1
解决办法
3616
查看次数

嵌套路由和form_for以及NoMethodError

正如下面所述的错误消息,我不使用"user_profiles_path"作为复数,因为我在嵌套资源中定义了"resource:profile".

NoMethodError in Profiles#new
Run Code Online (Sandbox Code Playgroud)

显示/home/smileymike/rails_projects/bffmapp_v2/app/views/profiles/new.html.erb其中线#20提出:

undefined method `user_profiles_path' for #<#<Class:0x90266ac>:0xa041294>
Run Code Online (Sandbox Code Playgroud)

模型:

class User < ActiveRecord::Base
  has_one :profile

class Profile < ActiveRecord::Base
  attr_accessible :name, :surname
  belongs_to :user
Run Code Online (Sandbox Code Playgroud)

routes.rb中:

  resources :users do
    resource :profile  (note: has_one)
  end
Run Code Online (Sandbox Code Playgroud)

查看:profiles/new.html.erb

<div class="row">
  <div class="span6 offset3">
    <%= form_for([@user, @profile]) do |f| %>
      <%= f.label :name %>
      <%= f.text_field :name %>

      <%= f.label :surname %>
      <%= f.text_field :surname %>

      <%= f.submit "Create my profile", class: "btn btn-large btn-primary" %>
    <% end %>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

路线

    user_profile …
Run Code Online (Sandbox Code Playgroud)

controller ruby-on-rails form-for nested-resources ruby-on-rails-3

2
推荐指数
1
解决办法
1098
查看次数

has_one嵌套路由和路由错误消息:"没有路由匹配[POST]"/ users/3/profiles""

提交"创建我的个人资料"后发生错误

路由错误

没有路由匹配[POST]"/ users/3/profiles"

其次,我重新启动了webbrick cli ="rails s",输入"http:// localhost:3000/users/1/profile/new"后,我收到错误消息"undefined method`user_profiles_path'".显然,我使用了"resource:profile"非嵌套资源.我正在撕扯我的头发,这些错误发生了什么?

<h1>About You</h1>
<div class="row">
  <div class="span6 offset3">
    <%= form_for ([@user, @profile]) do |f| %>
      <%= f.label :name, "First name:" %>
      <%= f.text_field :name %>
      <%= f.label :surname, "Surname:" %>
      <%= f.text_field :surname %>
      <%= f.submit "Create my profile", class: "btn btn-large btn-primary" %>
    <% end %>
  </div>
</div>

  resources :users do
    resource :profile
  end

     user_profile POST   /users/:user_id/profile(.:format)      profiles#create
 new_user_profile GET    /users/:user_id/profile/new(.:format)  profiles#new
edit_user_profile GET    /users/:user_id/profile/edit(.:format) profiles#edit
                  GET    /users/:user_id/profile(.:format)      profiles#show
                  PUT …
Run Code Online (Sandbox Code Playgroud)

routes ruby-on-rails form-for ruby-on-rails-3

2
推荐指数
1
解决办法
1176
查看次数