#3 楼 @tracyzhang 不太一样, 如 [email protected],your_email 为 [email protected],username 为 example
Devise 设置
# user.rb + confirmable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
# migration
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email # Only if using reconfirmable
add_index :users, :confirmation_token, unique: true
# devise.rb
config.mailer_sender = '<your_email>'
# Configure the class responsible to send e-mails.
config.mailer = 'Devise::Mailer'
Mailer 设置 Gmail 设置请查看Guides
# production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.163.com',
port: 25,
domain: 'mail.163.com',
user_name: '<username>',
password: '<password>',
authentication: :login
}
应该是你设置的 role,关联的 user 数量为 0,rolify 自动帮你清除掉了code
def remove(relation, role_name, resource = nil)
cond = { :name => role_name }
cond[:resource_type] = (resource.is_a?(Class) ? resource.to_s : resource.class.name) if resource
cond[:resource_id] = resource.id if resource && !resource.is_a?(Class)
roles = relation.roles.where(cond)
if roles
relation.roles.delete(roles)
roles.each do |role|
role.destroy if role.send(ActiveSupport::Inflector.demodulize(user_class).tableize.to_sym).limit(1).empty?
end if Rolify.remove_role_if_empty
end
roles
end
#4 楼 @drine 若你不需要反过来查到关联,可以不写;belongs_to 添加了以下一些方法:
A Post class declares belongs_to :author, which will add:
Post#author (similar to Author.find(author_id))
Post#author=(author) (similar to post.author_id = author.id)
Post#build_author (similar to post.author = Author.new)
Post#create_author (similar to post.author = Author.new; post.author.save; post.author)
Post#create_author! (similar to post.author = Author.new; post.author.save!; post.author)
#7 楼 @xiaozi0lei 谢了
:plus1: 正需要
👍
👍 学习了,pry 中_ex_
👍 ,希望 LZ 列出来一个能够直接帮助 Rails 开发的实例,总感觉原理概念什么的是使用之后的事情了
其实感觉最快的就是,找一个做这方面的朋友,让他给你稍微讲讲 ruby on rails tutorial,,然后就是把自己脑袋里面能问的全部问题,全部掏出来晒晒,应该很快就入门了,当然了自己鼓捣也是可以,就是慢点,也会忽略掉一些重要的知识。。。
可以换, 需要装 mysql,这样本地调试方便,
:plus1:
63
,添加个原因,以备后用:
Running Rack apps on 0.0.0.0 in development mode will allow malicious users on the local network (exf: a Coffee Shop or a Conference) to abuse or potentially exploit the app.Safer to default host to localhost when in development mode.
若你想查看当前项目的某个 gem 包安装位置:bundle show gem_name
若你想单独更新一个 gem 包,而不像修改 gemfile 和 gemfile.lock:bundle update gem_name
你可以直接将部署时 capitstrano 执行的最后出错命令,到你主机上直接执行进行调试。这类问题挺折腾的,所以以后还是将所有环境装在你部署时使用的用户环境中的好。
:plus1:
你的理解正确,可参考:https://ruby-china.org/topics/1050
star
看到这,只能默默的努力了....1..
:plus1: 不错,,
:plus1: ,呵呵,楼主厉害呀,不过使用的工具 tumblr 挺不错的,我使用 fengche.co 来管理进度,多看这个看书软件真不错 (wifi 传书),有道笔记做个笔记的也挺好的,发现在地铁里面看书有时候效率会出奇的好,哈哈
:plus1: 收藏,后续细细品读一下,谢谢分享
@flowerwrong ,这个链接很给力, :plus1:
我自己测了一下,有点超乎我的预计,呵呵,不过 Ruby 追求的不是性能
class EntryNormal
def e_0;end
def e_1;end
def e_2;end
def e_3;end
def e_4;end
end
class EntryNormal2
def e_0(x);x;end
def e_1(x);x;end
def e_2(x);x;end
def e_3(x);x;end
def e_4(x);x;end
end
class Entry
5.times do |i|
define_method("e_#{i}"){}
end
end
class Entry2
def initialize(n)
n.times do |i|
Entry2.define_component("e_#{i}")
end
end
def self.define_component(name)
define_method(name) do |x|
x
end
end
end
class Entry3
def method_missing(method, arg)
arg
end
end
require 'benchmark/ips'
Benchmark.ips do |x|
x.report("normal method") do
en = EntryNormal.new
en.e_0
en.e_1
en.e_2
en.e_3
en.e_4
end
x.report("normal method args") do
e = EntryNormal2.new
e.e_0(1)
e.e_1(2)
e.e_2(3)
e.e_3(4)
e.e_4(5)
end
x.report("method_missing") do
e = Entry3.new
e.e_0(1)
e.e_1(2)
e.e_2(3)
e.e_3(4)
e.e_4(5)
end
x.report("dynamic method") do
e = Entry.new
e.e_0
e.e_1
e.e_2
e.e_3
e.e_4
end
x.report("dynamic method args") do
e = Entry2.new(5)
e.e_0(1)
e.e_1(2)
e.e_2(3)
e.e_3(4)
e.e_4(5)
end
x.compare!
end
Result:
Calculating -------------------------------------
normal method 64.900k i/100ms
normal method args 63.045k i/100ms
method_missing 57.231k i/100ms
dynamic method 56.053k i/100ms
dynamic method args 5.584k i/100ms
-------------------------------------------------
normal method 2.084M (±10.7%) i/s - 10.319M
normal method args 1.801M (±11.1%) i/s - 8.889M
method_missing 1.495M (±13.5%) i/s - 7.326M
dynamic method 1.245M (±13.1%) i/s - 6.110M
dynamic method args 57.401k (±13.6%) i/s - 284.784k
Comparison:
normal method: 2084278.1 i/s
normal method args: 1801098.3 i/s - 1.16x slower
method_missing: 1494748.3 i/s - 1.39x slower
dynamic method: 1244953.5 i/s - 1.67x slower
dynamic method args: 57401.2 i/s - 36.31x slower
[Finished in 35.4s]
@jex 做这个主要的目的是什么呢?加密敏感词?
我这几天也正好遇到,ubuntu 单系统关不了机,卡在了 logo 页面,想来也是如上这些分析,回去查查电源管理问题,
:plus1:,支持你一个,若需要合作小伙伴可以加我一个