Jak*_*out 0 ruby ajax controller ruby-on-rails
我在我的控制器中有这个功能
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
Run Code Online (Sandbox Code Playgroud)
表单设置为remote:true所以这是我的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'
Run Code Online (Sandbox Code Playgroud)
知道为什么会出现这个错误吗?
如果要渲染create.js.erb,请尝试将此更改为此
format.js { render action: 'create', success: true, location: @tweet }
Run Code Online (Sandbox Code Playgroud)
简单地说
format.js
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
220 次 |
| 最近记录: |