Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- форма edit
- = title 'Редактирование числа спутников'
- = render partial: 'form', locals: {object: @datum}
- паршал
- .bi-column
- .center.mobile-padded
- .text-wrapper
- = simple_form_for @datum, url: admin_other_datum_path(@datum), method: :put do |f|
- = f.input :title
- = f.input :number
- - if can? :other_data_assign_roles, @user
- = f.input :roles, as: :check_boxes, collection: t('enum.permissions').stringify_keys.invert
- .buttons.mobile-padded
- = button_tag f.submit "Изменить", class: 'button'
- = params
- Контроллер
- class Admin::OtherDataController < Admin::AdminController
- authorize_resource
- # include Admin::CUDProcessing
- # self.object_class = OtherDatum
- def index
- @other_data_all = OtherDatum.all
- end
- def edit
- @datum = OtherDatum.friendly.find_or_initialize_by(slug: params[:id]) do |data|
- data.title = I18n.t(params[:id], scope: 'activerecord.attributes.other_datum.table', default: params[:id])
- data.number = 0
- data.slug = params[:id]
- end
- byebug
- end
- def update
- @datum = OtherDatum.friendly.find_or_initialize_by(slug: params[:id])
- # @datum = OtherDatum.friendly.find_or_initialize_by(slug: params[:id]) do |data|
- # data.title = params[:other_datum][:title]
- # data.number = params[:other_datum][:number]
- # data.roles = params[:other_datum][:roles]
- # data.slug = params[:id]
- # end
- byebug
- # if @datum.update(other_datum_params.merge(slug: params[:id]))
- if @datum.update(other_datum_params)
- redirect_to({:action => :index}, {:notice => 'Data updated'})
- else
- render :edit, id: params[:id]
- end
- end
- def other_datum_params
- params.require(:other_datum).permit(:title, :number, :roles, :slug)
- end
- end
- Модель
- class OtherDatum < ActiveRecord::Base
- include FriendlyId
- strip_attributes
- friendly_id :title, use: :slugged
- validates :title, :number, presence: true
- end
- Таблица
- create_table "other_data", force: :cascade do |t|
- t.string "title"
- t.integer "number"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "slug"
- t.string "roles", default: [], null: false, array: true
- t.index ["slug"], name: "index_other_data_on_slug", unique: true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement