assert_select "div" <div>foobar</div>
assert_select "div", "foobar" <div>foobar</div>
assert_select "div.nav" <div class="nav">foobar</div>
assert_select "div#profile" <div id="profile">foobar</div>
assert_select "div[name=yo]" <div name="yo">hey</div>
assert_select "a[href=?]", ’/’, count: 1 <a href="/">foo</a>
assert_select "a[href=?]", ’/’, text: "foo" <a href="/">foo</a>
rails generate devise:views
invoke Devise::Generators::SharedViewsGenerator
create app/views/devise/shared
create app/views/devise/shared/_links.html.erb
invoke form_for
create app/views/devise/confirmations
create app/views/devise/confirmations/new.html.erb
create app/views/devise/passwords
create app/views/devise/passwords/edit.html.erb
create app/views/devise/passwords/new.html.erb
create app/views/devise/registrations
create app/views/devise/registrations/edit.html.erb
create app/views/devise/registrations/new.html.erb
create app/views/devise/sessions
create app/views/devise/sessions/new.html.erb
create app/views/devise/unlocks
create app/views/devise/unlocks/new.html.erb
invoke erb
create app/views/devise/mailer
create app/views/devise/mailer/confirmation_instructions.html.erb
create app/views/devise/mailer/reset_password_instructions.html.erb
create app/views/devise/mailer/unlock_instructions.html.erb
home_about GET /home/about(.:format) home#about
home_team GET /home/team(.:format) home#team
home_help GET /home/help(.:format) home#help
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_omniauth_authorize GET|POST /users/auth/:provider(.:format) devise/omniauth_callbacks#passthru {:provider=>/(?!)/}
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) devise/omniauth_callbacks#:action
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
root GET / home#index
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
debugger#调试器
end
def new
end
end
改写devise的controller
devise_for :users, :controllers => {:registrations => "devise_customed/registrations"}
之后继承改写
class DeviseCustomed::RegistrationsController < Devise::RegistrationsController
def new
super
end def create
# add custom create logic here
super do |resource|
resource.group = params[:user][:group]
end
end def update
super
end
健壮参数,修改registrations_controller.rb
class DeviseCustomed::RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
@user = User.new(user_params)
if @user.save else
render 'new'
end
# add custom create logic here
super do |resource|
resource.group = params[:user][:group]
end
end
def update
super
end private
def user_params
params.require(:user).premit(:name, :name, :encrypted_password)
end
end
pluralize 方法的第一个参数是整数,返回值是这个数字和第二个参数组合在一起后,正确的单
复数形式。
注册成功
添加
if @user.save
redirected_ro @user
else
render 'new'
end
当修改
config.authentication_keys = [ :username]
提交信息会报错,那么添加
protected def email_required?
false
end
这种是不要email的情况,如果要email的话还要添加
config.authentication_keys = [ :username, :email ]
SQLiteException: database is locked异常的解决办法
文件数据库sqlite,同一时刻允许多个进程/线程读,但同一时刻只允许一个线程写。 在操行写操作时,数据库文件被琐定,此时任何其他读/写操作都被阻塞,如果阻塞超过5秒钟(默认是5秒,能过重新编译sqlite可以修改超时时间),就 报"database is locked"错误。
所以,在操作sqlite时,应该即时关闭连接;打开连接后,尽量减少非常费时的操作。
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :mailer_set_url_options
before_action :configure_permitted_parameters, if: :devise_controller? def mailer_set_url_options
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :name #修改参数,可以在表里添加name
end
end
修改之后,最好重启server,然后rake db:migrate:reset