Commit ee5dc167 by Mykhailo Makohin

create project model and cunstomize some activeadmin templates

parent f6334a88
...@@ -27,6 +27,7 @@ gem 'simple_form' ...@@ -27,6 +27,7 @@ gem 'simple_form'
gem 'activeadmin' gem 'activeadmin'
gem 'carrierwave' gem 'carrierwave'
gem 'cancancan' gem 'cancancan'
gem 'cocoon'
group :development, :test do group :development, :test do
gem 'byebug', platform: :mri gem 'byebug', platform: :mri
......
...@@ -76,6 +76,7 @@ GEM ...@@ -76,6 +76,7 @@ GEM
image_processing (~> 1.1) image_processing (~> 1.1)
mimemagic (>= 0.3.0) mimemagic (>= 0.3.0)
mini_mime (>= 0.1.3) mini_mime (>= 0.1.3)
cocoon (1.2.14)
coffee-rails (4.2.2) coffee-rails (4.2.2)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0) railties (>= 4.0.0)
...@@ -184,8 +185,6 @@ GEM ...@@ -184,8 +185,6 @@ GEM
activerecord (>= 5.0) activerecord (>= 5.0)
public_suffix (4.0.1) public_suffix (4.0.1)
puma (3.12.1) puma (3.12.1)
pundit (2.1.0)
activesupport (>= 3.0.0)
rack (2.0.7) rack (2.0.7)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
...@@ -291,6 +290,7 @@ DEPENDENCIES ...@@ -291,6 +290,7 @@ DEPENDENCIES
byebug byebug
cancancan cancancan
carrierwave carrierwave
cocoon
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
devise devise
gmaps4rails gmaps4rails
...@@ -304,7 +304,6 @@ DEPENDENCIES ...@@ -304,7 +304,6 @@ DEPENDENCIES
omniauth-google-oauth2 omniauth-google-oauth2
omniauth-linkedin-oauth2 omniauth-linkedin-oauth2
puma (~> 3.0) puma (~> 3.0)
pundit
rails (~> 5.0.7, >= 5.0.7.2) rails (~> 5.0.7, >= 5.0.7.2)
remotipart remotipart
sass-rails (~> 5.0) sass-rails (~> 5.0)
......
ActiveAdmin.register Project do
menu label: 'Project'
controller do
def permitted_params
params.permit(:utf8, :_method, :authenticity_token, :locale, :commit, :id,
project: [:photo, :photo_preview, :photo_before, :photo_after, :type,
:status, :name, :name_eng, :individual_type_ua, :individual_type_en,
:title_ua, :title_en, :heading_ua, :heading_en, :slug, :short_description_ua,
:short_description_en, :locale, :description_ua,:description_en, :site,
:link_to_facebook, :required_amount, :related_links_ua, :related_links_en,
:footer_photo, project_galeries_attributes: [:id, :photo, :name_uk, :name_en, :_destroy]])
end
end
form do |f|
f.inputs do
f.input :photo, label: "Photo"
f.input :photo_preview, label: "Preview for main page"
f.input :name, label: "Name"
# f.input :location, label: "#{t "active_admin.attributes.user.location"}"
# f.input :password, label: "#{t "active_admin.attributes.user.password"}"
# f.input :password_confirmation, label: "#{t "active_admin.attributes.user.password_confirmation"}"
# f.input :role, as: :select, collection: User.roles.map { |role| [I18n.t("active_admin.user/role.#{role[0]}"), role[0]] },
# label: (t "active_admin.attributes.user.role")
# f.input :avatar, label: "#{t "active_admin.attributes.user.avatar"}"
end
f.actions
end
end
...@@ -28,3 +28,4 @@ ...@@ -28,3 +28,4 @@
//= require infobox //= require infobox
//= require squares //= require squares
//= require_tree . //= require_tree .
//= require cocoon
class ProjectsController < ApplicationController
load_and_authorize_resource
def index
@projects = collection
end
def show
@project = Project.new
end
def new
@project = Project.new
end
def create
@project = Project.create(project_params)
if @project.save
redirect_to projects_path
else
render :new
end
end
def edit
@project = resource
end
def update
@project = resource
if @project.update(project_params)
redirect_to project_path(project: @project)
else
render :edit
end
end
def destroy
@project = resource
@project.destroy
redirect_to projects_path
end
private
def collection
Project.all
end
def resource
Project.find(params[:id])
end
def user_params
params.require(:project).permit(:photo, :photo_preview, :photo_before, :photo_after, :type,
:status, :name, :name_eng, :individual_type_ua, :individual_type_en,
:title_ua, :title_en, :heading_ua, :heading_en, :slug, :short_description_ua,
:short_description_en, :description_ua,:description_en, :site,
:link_to_facebook, :required_amount, :related_links_ua, :related_links_en,
:footer_photo)
end
end
\ No newline at end of file
...@@ -15,6 +15,7 @@ class Ability ...@@ -15,6 +15,7 @@ class Ability
can :index, :home can :index, :home
# User related abilities # User related abilities
can :manage, User can :manage, User
can :manage, Project
end end
end end
end end
class Project < ApplicationRecord
has_many :project_galeries, dependent: :destroy
accepts_nested_attributes_for :project_galeries, reject_if: :all_blank, allow_destroy: true
mount_uploader :photo, AvatarUploader
mount_uploader {:photo_preview, :photo_before}, AvatarUploader
validates :status, :name, :short_description_ua,
:description_ua, :required_amount, presence: true
enum type: [:program, :project]
enum status: [:in_progress, :implemented]
end
class ProjectGalery < ApplicationRecord
belongs_to :project
end
Rails.application.routes.draw do Rails.application.routes.draw do
scope "(:locale)", locale: /en|uk/ do scope "(:locale)", locale: /en|uk/ do
root 'home#index' root 'home#index'
resources :users
ActiveAdmin.routes(self) ActiveAdmin.routes(self)
resources :users
resources :projects
end end
devise_for :users, controllers: {omniauth_callbacks: "users/omniauth_callbacks", devise_for :users, controllers: {omniauth_callbacks: "users/omniauth_callbacks",
registrations: "users"} registrations: "users"}
......
class CreateProjects < ActiveRecord::Migration[5.0]
def change
create_table :projects do |t|
t.string :photo
t.string :photo_preview
t.string :photo_before
t.string :photo_after
t.integer :type
t.integer :status
t.string :name
t.string :name_eng
t.string :individual_type_ua
t.string :individual_type_en
t.string :title_ua
t.string :title_en
t.string :heading_ua
t.string :heading_en
t.string :slug
t.text :short_description_ua
t.text :short_description_en
t.text :description_ua
t.text :description_en
t.string :site
t.string :link_to_facebook
t.float :required_amount
t.string :related_links_ua
t.string :related_links_en
t.string :footer_photo
t.timestamps
end
end
end
class CreateProjectGaleries < ActiveRecord::Migration[5.0]
def change
create_table :project_galeries do |t|
t.string :photo
t.string :name_uk
t.string :name_en
t.timestamps
end
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190911111638) do ActiveRecord::Schema.define(version: 20190925121437) do
create_table "active_admin_comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "active_admin_comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "namespace" t.string "namespace"
...@@ -26,6 +26,44 @@ ActiveRecord::Schema.define(version: 20190911111638) do ...@@ -26,6 +26,44 @@ ActiveRecord::Schema.define(version: 20190911111638) do
t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree
end end
create_table "project_galeries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "photo"
t.string "name_uk"
t.string "name_en"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "projects", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "photo"
t.string "photo_preview"
t.string "photo_before"
t.string "photo_after"
t.integer "type"
t.integer "status"
t.string "name"
t.string "name_eng"
t.string "individual_type_ua"
t.string "individual_type_en"
t.string "title_ua"
t.string "title_en"
t.string "heading_ua"
t.string "heading_en"
t.string "slug"
t.text "short_description_ua", limit: 65535
t.text "short_description_en", limit: 65535
t.text "description_ua", limit: 65535
t.text "description_en", limit: 65535
t.string "site"
t.string "link_to_facebook"
t.float "required_amount", limit: 24
t.string "related_links_ua"
t.string "related_links_en"
t.string "footer_photo"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment