当我在请求中明确指定remote: true
时,不确定为什么有些用户有时会出现缺少模板错误。我无法重现错误。
缺少appreciations/create
,logged_in/create
,application/create
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :haml]}
的模板。搜索:...
我的观看代码
<%= link_to 'Appreciate', feed_appreciations_path(feed), method: 'post', :remote => true %>
控制器代码
class AppreciationsController
respond_to :js
before_filter :load_feed
def create
@appreciation = @feed.appreciations.new(params[:appreciation])
@appreciation.save
end
...
end
我已views/appreciations/create.js.erb
定义并正在使用。
在我的请求中
HTTP_ACCEPT : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
action_dispatch.request.formats : [text/html]
为什么请求不是js请求,因为我已经指定了remote: true
?
答案 0 :(得分:0)
好的,这是答案
def your_method_without_refresh
# Put your stuff here
redirect_to "#" # This one is the trick
end
答案 1 :(得分:-1)
因为他们试图直接在浏览器中调用网站 - 例如因为他们以某种方式从AJAX请求中复制了URL ...至少这是客户这样做时的错误;-)我想你可以简单地忽略它