我最近买了一台Mac,它使用Mac OSX El Capitan v10.11.4.使用自制软件安装节点,并使用节点v6.2.2和npm v3.9.5.我在使用bcrypt时遇到错误npm install,我认为这是由node-gyp rebuild错误引起的.我最近也下载了xcode-select(版本2343)和xcode(7.3.1)(按此顺序).
这是我运行后的完整错误输出npm install:
https://gist.github.com/varunjayaraman/5734af617d616437cd5b3456b20bc503
不确定出了什么问题.我来自linux的土地,并且确实对自己不从源代码安装保持警惕,所以也许这就是导致这些问题的原因?无论如何,任何建议都会受到超级赞赏.我也看到这个错误在其他人身上涌现,但他们的解决方案似乎都没有用(当我输入时xcode-select --print-path,我得到了/Applications/Xcode.app/Contents/Developer)
我在理解 Rails 的会话和身份验证时遇到了很多麻烦。所以基本上,我尝试根据书中的教程设置基于 user_id 的会话。这是我的 session_controller.rb 文件中的 create 方法:
def create
if user = User.authenticate(params[:email], params[:password])
session[:id] = user.id
redirect_to root_path, :notice => 'Logged in successfully'
else
flash.now[:alert] = "Invalid login/password combination"
render :action => 'new'
end
Run Code Online (Sandbox Code Playgroud)
结尾
但是,当我尝试在 application_controller.rb 文件中定义 current_user 方法时,它要求我根据 user_id 引用会话:
def current_user
return unless session[:user_id]
@current_user = User.find_by_id(session[:user_id])
end
Run Code Online (Sandbox Code Playgroud)
这让我感到困惑 - user_id 是每个食谱(相当于我的应用程序中的文章或帖子)的一个属性,它与用户创建了 has_one 关系。我的应用程序中没有其他地方定义了 user_id。所以 user_id 不应该是用户的属性,对吗?
为了澄清起见,我已经从 rails 控制台列出了 User 对象和 Recipe 对象的参数:
2.0.0-p598 :019 > Recipe
=> Recipe(id: integer, title: string, body: …Run Code Online (Sandbox Code Playgroud)