2015-09-12 3 views
0

мне нужно встроенное редактирование, создание и обновление в одном месте batch_notifications.controller.rbКак показать создание записи и показать в том же месте, используя лучшие на месте в рельсах?

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 

index.html.erb

<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> 

batchnotification.rb

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 

Как показать создание и показать в том же месте в рельсах.

Примечание: предположим, что я создаю сообщение в окне сообщения и нажимаю Enter, он будет отображаться в том же месте. Как это возможно, пожалуйста, помогите мне, как это сделать.

+0

Вы можете прикрепить снимок здесь? –

+0

вы можете сделать это, хотя ajax easliy –

+0

Хорошо спасибо, я получил его – Kiran

ответ

0

Изменить мой index.html.erb найти это решение через если другое условие

<% if [email protected]_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 %> 
Смежные вопросы