Rails JQuery和Ajax对我来说工作不正常
Rails JQuery and Ajax not working properly for me?
因此,我所拥有的基本上是business
模型的显示页面,它显示了业务的各个信息。我所做的是创建一个编辑按钮,基本上显示各个字段的表单并隐藏实际信息。然而,我现在遇到的问题是,当我进行编辑并提交表单时,信息没有被"刷新",我必须手动刷新页面才能看到更改。我对这件事还很陌生,事实上我最近才开始工作,我很想知道我做得不对。我在youtube上观看了一段解释Jquery和Ajax的视频,但我正在做一些更改,试图让它根据我的需要发挥作用。
显示查看页面
<%= form_for(@business, remote: true) do |f| %>
//.... omited for clarity
<div id="business-info-section">
<h4><%= @business.name %></h4>
<p><%= @business.description %></p>
</div>
<!-- This will display only when the edit button is clicked (SHOW THE BUIZ FORM FIELD) -->
<div id="business-info-section-edit">
<div class="field">
<%= f.text_field :name, class:"form-control" %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description , class:"form-control" %>
</div>
</div>
</div>
</div>
<div class="col-md-9">
<!-- show option only if curr user == show profile user -->
<%= image_tag @business.header_img.url(:large), class:"center-block", id:"header_img" %>
<div class="row edit-btns">
<div class="col-md-12">
<!-- this is the edit profile button that toggles jQuery methods -->
<%= link_to 'Edit Profile', "#", class: "btn btn-primary pull-right", id: "edit-profile-btn" %>
<%= f.submit 'Save Profile', class: "btn btn-primary pull-right", id: "save-profile-btn" %>
</div>
</div>
业务控制器
def update
if @business.update(business_params)
respond_to do |format|
format.html { redirect_to @business, notice: 'Business was successfully updated.' }
format.js #render businesses/update.js.erb
end
else
render :edit
end
end
businesss/update.js.erb文件
$('#business-info-section').append('<%= j render user_profile_path(@business.user_id, @business.user.email) %>');
更改表单的此部分-
<div id="business-info-section">
<h4><%= @business.name %></h4>
<p><%= @business.description %></p>
</div>
到这个-
创建一个部分:_business_detail.html.erb
<h4><%= @business.name %></h4> <p><%= @business.description %></p>
现在以的形式呈现上面的部分
<div id="business-info-section"> <%= render 'business_detail'%> </div>
将业务/update.js.erb文件更新到此-
$('#business-info-section').html('<%= j render 'business_detail' %>');
相关文章:
- Javascript.getHours()工作不正常
- removeClass函数没有'工作不正常
- jQuery Ajax GET请求工作不正常
- Cordova ng路线工作不正常
- 更新属性工作不正常Meteor/MongoDB
- 为什么文本对齐:对;工作不正常
- Javascript作用域和Ajax调用;工作不正常
- JavaScript DOM insertBefore'工作不正常
- Angular Js布线工作不正常
- onmouseout函数工作不正常
- 承诺工作不正常
- JQuery.live()工作不正常
- Alloy UI文本区域工作不正常
- ng src工作不正常,但src工作正常
- Canvas.toDataUrl(“image/png”)工作不正常
- JQuery `length`属性工作不正常.为什么?
- Javascript setInterval工作不正常
- 我的Javascript代码没有'工作不正常
- 表单验证工作不正常,在不检查条目的情况下继续
- $localStorage array select with ng选项工作不正常