2015-07-19 100 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

是啊你的答案解決了問題:) –