Rails New Model Ajax Response
Rails New Model Ajax Response
我正在尝试在新表单上制作一个简单的示例,以便在使用 ajax 创建新项目时发送成功通知。我收到来自服务器的响应,其中包含 500 内部错误。
新.js.erb
$("#flash-messages").html("<%= notice %>")
新.html.erb
<h1>New Ajax</h1>
<%= form_for(@ajax, remote: true) do |f| %>
<div id="flash-messages" >
</div>
<% if @ajax.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@ajax.errors.count, "error") %> prohibited this ajax from being saved:</h2>
<ul>
<% @ajax.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
控制器
def create
@ajax = Ajax.new(ajax_params)
respond_to do |format|
if @ajax.save
format.html { redirect_to @ajax, notice: 'Ajax was successfully created.' }
format.json { render :show, status: :created, location: @ajax }
format.js { redirect_to new_ajax_path, flash[:notice] = "Fudeu" }
else
format.html { render :new }
format.json { render json: @ajax.errors, status: :unprocessable_entity }
end
end
结束
我找到了为什么会窃听我的代码。只是 nee 删除闪光灯[:通知] 以注意:现在我正在考虑给这个闪光灯一个生命,比如10秒,它就消失了。当我让它工作时,我会把它发布在这里给其他可能像我一样挣扎的人
相关文章:
- jQuery ajax cache response
- JQuery Ajax does not response to Node JS
- JSON and AJAX response
- ajax response run javascript
- Jquery ajax POST response is null
- Javascript AJAX POST Response
- Rails New Model Ajax Response
- Jquery AJAX response JSON in variable.
- Ajax XML response is NULL
- jQuery on method with ajax response
- extjs ajax response with python bottle
- IE8 & 9 - no jquery ajax response object
- jQuery/Javascript/AJAX response:将字符串而不是 int 传递到函数中
- JavaScript in AJAX Response
- django-ajax json response
- Ajax response PHP echo HTML
- 如何返回response.valid而不是response.d ASP.NET ajax
- Ajax response is null
- 同时使用“数据”和“数据”.和“;response"属性中的ajax调用
- Ruby on Rails, json vs js ajax response