Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. форма edit
  2. = title 'Редактирование числа спутников'
  3. = render partial: 'form', locals: {object: @datum}
  4.  
  5. паршал
  6.  
  7. .bi-column
  8. .center.mobile-padded
  9.  
  10. .text-wrapper
  11. = simple_form_for @datum, url: admin_other_datum_path(@datum), method: :put do |f|
  12. = f.input :title
  13. = f.input :number
  14.  
  15. - if can? :other_data_assign_roles, @user
  16. = f.input :roles, as: :check_boxes, collection: t('enum.permissions').stringify_keys.invert
  17.  
  18.  
  19. .buttons.mobile-padded
  20. = button_tag f.submit "Изменить", class: 'button'
  21. = params
  22.  
  23. Контроллер
  24.  
  25. class Admin::OtherDataController < Admin::AdminController
  26.  
  27. authorize_resource
  28. # include Admin::CUDProcessing
  29. # self.object_class = OtherDatum
  30.  
  31. def index
  32. @other_data_all = OtherDatum.all
  33. end
  34.  
  35. def edit
  36. @datum = OtherDatum.friendly.find_or_initialize_by(slug: params[:id]) do |data|
  37. data.title = I18n.t(params[:id], scope: 'activerecord.attributes.other_datum.table', default: params[:id])
  38. data.number = 0
  39. data.slug = params[:id]
  40. end
  41. byebug
  42. end
  43.  
  44. def update
  45. @datum = OtherDatum.friendly.find_or_initialize_by(slug: params[:id])
  46. # @datum = OtherDatum.friendly.find_or_initialize_by(slug: params[:id]) do |data|
  47. # data.title = params[:other_datum][:title]
  48. # data.number = params[:other_datum][:number]
  49. # data.roles = params[:other_datum][:roles]
  50. # data.slug = params[:id]
  51. # end
  52. byebug
  53. # if @datum.update(other_datum_params.merge(slug: params[:id]))
  54. if @datum.update(other_datum_params)
  55. redirect_to({:action => :index}, {:notice => 'Data updated'})
  56. else
  57. render :edit, id: params[:id]
  58. end
  59. end
  60.  
  61. def other_datum_params
  62. params.require(:other_datum).permit(:title, :number, :roles, :slug)
  63. end
  64.  
  65. end
  66.  
  67. Модель
  68.  
  69. class OtherDatum < ActiveRecord::Base
  70. include FriendlyId
  71. strip_attributes
  72. friendly_id :title, use: :slugged
  73.  
  74. validates :title, :number, presence: true
  75.  
  76. end
  77.  
  78. Таблица
  79.  
  80. create_table "other_data", force: :cascade do |t|
  81. t.string "title"
  82. t.integer "number"
  83. t.datetime "created_at", null: false
  84. t.datetime "updated_at", null: false
  85. t.string "slug"
  86. t.string "roles", default: [], null: false, array: true
  87. t.index ["slug"], name: "index_other_data_on_slug", unique: true
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement