2015-07-19 102 views
0

未定义的方法我有这个功能在我的控制器红宝石NoMethodError - 在控制器

def create 
    @tweet = Tweet.new(tweet_params) 
    @tweet.user_id = current_user.id 

    respond_to do |format| 

     if @tweet.save 
      format.html { redirect_to root_path, notice: "hello" } 
      format.js { render action: 'create', success: true, location: @tweet } 
     else 
      format.html { render action: 'show' } 
      format.js { render action: 'create', success: false } 
     end 

    end 

end 

形式设置为远程:真正的,所以这是我的create.js.erb

,但我得到了他的错误

NoMethodError (undefined method `tweet_url' for #<TweetsController:0x007f8de60e4b58>): 
    app/controllers/tweets_controller.rb:13:in `block (2 levels) in create' 
    app/controllers/tweets_controller.rb:9:in `create' 

任何想法为什么这个错误显示?

+0

能否请您发表您的routes文件尝试修改此来这样做呢? –

+0

我认为这与'location:@ tweet'有关? – adamliesko

回答

5

,如果你想渲染create.js.erb

format.js { render action: 'create', success: true, location: @tweet } 

简单此

format.js 
+0

我想我的答案会解决问题。但也可以告诉我你的create.js.erb – Athar

+0

是啊你的答案解决了问题:) –