好的,感谢你的帮助,我再多研究一下!谢谢啦
噢,我突然好像明白了,这个 Sample 里面用到了一个 Cucumber 黄瓜的东东。
补充一下,还有一个文件是 signing_in.feature 这个.feature 的后缀之前没见过啊,里面的内容是
Feature: Signing in
Scenario: Unsuccessful signin
Given a user visits the signin page
When he submits invalid signin information
Then he should see an error message
Scenario: Successful signin
Given a user visits the signin page
And the user has an account
And the user submits valid signin information
Then he should see his profile page
And he should see a signout link
OK,都是没有 reload 惹的祸呐!!!辛苦各位啦
已经这样做了,还是不行。。。。
class User < ActiveRecord::Base attr_accessible :email, :unn
has_many :microposts, :foreign_key => 'user_uid' end
感觉这是个 BUG?无解了?
还是没办法改过来
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'microposts.user_id' in 'where clause': SELECT microposts
.* FROM microposts
WHERE microposts
.user_id
= 1
@Ddl1st 我这样操作了,还是不行。
外键错了?能详细说说吗?
在我的 microposts 表里面,是没有 user_id 这个字段的,我是设置的 user_uid 这个字段
重要的错误提示我觉得应该是这句
first_user.microposts
Micropost Load (0.3ms)ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column SELECT microposts
.* FROM microposts
WHERE microposts
.user_id
= 1
'microposts.user_id'Mysql2::Error: Unknown column 'microposts.user_id' in 'where clause': SELECT microposts
.* FROM microposts
WHERE microposts
.user_id
= 1
in 'where clause': SELECT microposts
.* FROM microposts
WHERE microposts
.user_id
= 1
检查了,那个没问题。
first_user.email(不是 first.user.email,笔误)
first_user.micropost.content
NoMethodError: undefined method micropost' for #<User:0x00000101c38320>
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/activemodel-3.2.3/lib/active_model/attribute_methods.rb:407:in
method_missing'
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.3/lib/active_record/attribute_methods.rb:148:in method_missing'
from (irb):31
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in
start'
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in start'
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands.rb:41:in
'
from /Users/JasonJiang/ror/TestSQL/script/rails:6:in require'
from /Users/JasonJiang/ror/TestSQL/script/rails:6:in
'
from -e:1:in load'
from -e:1:in
没有的,显示如下:
irst_user.micropost.content
NoMethodError: undefined method micropost' for #<User:0x00000101c38320>
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/activemodel-3.2.3/lib/active_model/attribute_methods.rb:407:in
method_missing'
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.3/lib/active_record/attribute_methods.rb:148:in method_missing'
from (irb):31
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in
start'
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in start'
from /Users/JasonJiang/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.3/lib/rails/commands.rb:41:in
'
from /Users/JasonJiang/ror/TestSQL/script/rails:6:in require'
from /Users/JasonJiang/ror/TestSQL/script/rails:6:in
'
from -e:1:in load'
from -e:1:in
啊。已经创建了啊。
找到原因了,需要在.bash_profile 里设置一下就行了。希望大家以后遇到这个问题,能轻松解决啊
@hujoy 精辟!