简体   繁体   中英

Ruby NoMethodError - undefined method in controller

I have this function in my controller

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

the form is set to remote: true so this is my create.js.erb

but I got his error

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'

any idea why is this error displaying?

try changing this to to this if you want to render create.js.erb

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

to simply this

format.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM