P
P
Pavel Grudinkin2016-07-11 05:02:47
Ruby on Rails
Pavel Grudinkin, 2016-07-11 05:02:47

How to edit a boolean type field with checkboxes for several records of the same model in one form at once?

There is a table, one of the boolean type fields. You need to display a list of records from this table on the page and be able to edit this field by putting checkboxes and saving by clicking on one submit button. How to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)

do it with ajax

class EatShitController < ApplicationController
  # some code
  def lets_eat
    TriggerForYourPeaceOfShit.call(params[:ids]) # здесь передаешь массив
  end
end


class TriggerForYourPeaceOfShit
  def call(ids)
    YourShittyModel.where(id: ids).each do |your_object|
       your_object.toggle(:some_boolean_crap)
    end
  end
end

there still register the route and do other shit at the front. Too lazy to explain to you, you didn't even google

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question