Jquery 如何使用rails中的最佳就地显示创建的记录和在同一位置显示?
我需要在线编辑,创建和更新在同一个地方 批处理通知.controller.rbJquery 如何使用rails中的最佳就地显示创建的记录和在同一位置显示?,jquery,ruby-on-rails,ajax,Jquery,Ruby On Rails,Ajax,我需要在线编辑,创建和更新在同一个地方 批处理通知.controller.rb class BatchNotificationsController < ApplicationController before_action :set_batch_notification, only: [:show, :edit, :update, :destroy] respond_to :html def index @batch_notification
class BatchNotificationsController < ApplicationController
before_action :set_batch_notification, only: [:show, :edit, :update, :destroy]
respond_to :html
def index
@batch_notification = BatchNotification.new
@batch_notifications = BatchNotification.all
@final_count = []
@calculated_batch_counts = CalculatedBatchCount.all.group_by{|x| x.batch.batch_number if !x.batch.nil? }
@a = CalculatedBatchCount.all.group_by{|k| k.batch.serial_id if !k.batch.nil? }
puts "JAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAIJAI"
puts @a.inspect
@calculated_batch_counts.each do |key, values|
count = values.map{|x| x.finalCount}.length
h = {"batch_number" => key, "batch_id" => values.map{|x| x.batch.serial_id},"finalcount" => values.map{|x| x.finalCount}.sum(:+)/count}
@final_count << h
end
# => render :json => @final_count and return
respond_with(@batch_notifications)
end
def show
respond_with(@batch_notification)
end
def new
@batch_notification = BatchNotification.new
respond_with(@batch_notification)
end
def edit
end
def create
@batch_notification = BatchNotification.new(batch_notification_params)
respond_to do |format|
if @batch_notification.save
format.html { redirect_to :batch_notifications_path, notice: 'Vehicle was successfully created.' }
format.json { render action: 'index', status: :created, location: @batch_notification }
format.js
else
format.js
format.html { render action: 'new' }
format.json { render json: @batch_notification.errors, status: :unprocessable_entity }
end
end
end
def update
@batch_notification.update(batch_notification_params)
respond_to do |format|
format.js
end
end
def destroy
@batch_notification.destroy
respond_with(@batch_notification)
end
private
def set_batch_notification
@batch_notification = BatchNotification.find(params[:id])
end
def batch_notification_params
params.require(:batch_notification).permit(:message,:approved,:finalCount, :batch_id)
end
end
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>Listing Notifications</h5>
<div class="ibox-tools">
</div>
</div>
<div class="ibox-content">
<table class="table table-striped table-bordered" id="batchnote">
<thead>
<th>Batch</th>
<th>Final count</th>
<th>Approved</th>
<th>Message</th>
</thead>
<tbody>
<% @final_count.each do |x| %>
<tr>
<td ><%= x["batch_number"] %></td>
<td><%= x["finalcount"] %></td>
<% @batch = Batch.find_by(:batch_number => x["batch_number"])%>
<%= simple_form_for(@batch_notification , remote: true) do |f| %>
<td ><%= f.check_box :approved, label: false, class: "box-control" , :input_html => {value: @batch_notification.approved}%></td>
<td id = "<%= @batch.id %>" class ="notification_view"><%= f.input :message, label: false, placeholder:"message", class: "form-control" , :input_html => {value: @batch_notification.message}%> </td>
<td><%= f.input :batch_id, as: :hidden, :input_html => {value: @batch.id} %></td>
<%end%>
</tr>
</tbody>
<% end %>
</table>
</div>
</div>
</div>
</div>
</div>
class BatchNotification
include Mongoid::Document
include Mongoid::Timestamps
field :finalCount, type: Float
field :message, type: String
field :approved, type: String
field :batch_id, type: Integer
belongs_to :batch
end
如何在rails中的相同位置显示创建和显示
注意:假设我正在消息框中创建消息,并按enter键,它将显示在相同的位置。如何可能,请帮助我如何继续。更改my index.html.erb以通过if-else条件找到此解决方案
<% if !@batch.batch_notifications.blank? %>
<% @batch.batch_notifications.each do |notification| %>
<%= simple_form_for(@batch_notification , remote: true) do |f| %>
<% if notification.approved? %>
<td><%= best_in_place notification ,:approved , as: :checkbox %></td>
<% else %>
<td ><%= f.check_box :approved, label: false, class: "box-control" , :input_html => {value: @batch_notification.approved}%></td>
<% end %>
<% if !notification.message.nil? %>
<td><%= best_in_place notification, :message %></td>
<% else %>
<td id = "<%= @batch.id %>" class ="notification_view"><%= f.input :message, label: false, placeholder:"message", class: "form-control" , :input_html => {value: @batch_notification.message}%> </td>
<% end %>
<%= f.input :batch_id, as: :hidden, :input_html => {value: @batch.id} %>
<%end%>
<% end %>
<% else %>
<%= simple_form_for(@batch_notification , remote: true) do |f| %>
<td ><%= f.check_box :approved, label: false, class: "box-control" , :input_html => {value: @batch_notification.approved}%></td>
<td id = "<%= @batch.id %>" class ="notification_view"><%= f.input :message, label: false, placeholder:"message", class: "form-control" , :input_html => {value: @batch_notification.message}%> </td>
<%= f.input :batch_id, as: :hidden, :input_html => {value: @batch.id} %>
<% end %>
<% end %>
</tr>
</tbody>
<% end %>
{值:@batch_notification.approved}%>
{值:@batch_notification.message}%>
{value:@batch.id}%>
{值:@batch_notification.approved}%>
{值:@batch_notification.message}%>
{value:@batch.id}%>
您能将快照附加到这里吗?您可以通过ajax easliyOk实现这一点谢谢我得到了它