Class: Uchi::RepositoryController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Uchi::RepositoryController
- Includes:
- Pagination::Controller
- Defined in:
- app/controllers/uchi/repository_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from Pagination::Controller
Instance Method Details
#create ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/uchi/repository_controller.rb', line 11 def create @record = build_record if @record.save flash[:success] = @repository.translate.successful_create redirect_to(@repository.routes.path_for(:show, id: @record.id), status: :see_other) else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/uchi/repository_controller.rb', line 21 def destroy @record = find_record if @record.destroy flash[:success] = @repository.translate.successful_destroy redirect_to(@repository.routes.path_for(:index), status: :see_other) else flash[:alert] = @repository.translate.failed_destroy redirect_to(@repository.routes.path_for(:show, id: @record.id), status: :see_other) end end |
#edit ⇒ Object
32 33 34 |
# File 'app/controllers/uchi/repository_controller.rb', line 32 def edit @record = find_record end |
#index ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/uchi/repository_controller.rb', line 36 def index if params[:scope] # Handle being shown inline in another record's show view parent_repository = Uchi::Repository.for_model(params[:scope][:model])&.new parent_record = parent_repository.find(params[:scope][:id]) field_name = params[:scope][:field] inverse_of = params[:scope][:inverse_of]&.to_sym @columns = @repository.fields_for_index @columns = @columns.reject { |field| field.name == inverse_of } if inverse_of @records = find_all_records_from_association(name: field_name, parent_record: parent_record) @paginator, @records = paginate(@records, records_per_page: scoped_records_per_page) else # Handle the normal case @columns = @repository.fields_for_index @records = find_all_records @paginator, @records = paginate(@records, records_per_page: index_records_per_page) end end |
#new ⇒ Object
56 57 58 |
# File 'app/controllers/uchi/repository_controller.rb', line 56 def new @record = build_record end |
#show ⇒ Object
60 61 62 |
# File 'app/controllers/uchi/repository_controller.rb', line 60 def show @record = find_record end |
#update ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/uchi/repository_controller.rb', line 64 def update @record = find_record if @record.update(record_params) flash[:success] = @repository.translate.successful_update redirect_to(@repository.routes.path_for(:show, id: @record.id, uniq: rand), status: :see_other) else render :edit, status: :unprocessable_entity end end |