diff --git a/app/controllers/records_controller.rb b/app/controllers/records_controller.rb index 0d2881e..d90fea7 100644 --- a/app/controllers/records_controller.rb +++ b/app/controllers/records_controller.rb @@ -1,56 +1,56 @@ class RecordsController < ApplicationController before_action :set_domain before_action :set_record, only: [:edit, :update, :destroy] # GET /records/new def new @record = @domain.records.build end # GET /records/1/edit def edit end # POST /records def create @record = @domain.records.new(new_record_params) if @record.save redirect_to @domain, notice: 'Record was successfully created.' else render :new end end # PATCH/PUT /records/1 def update if @record.update(edit_record_params) redirect_to @domain, notice: 'Record was successfully updated.' else render :edit end end # DELETE /records/1 def destroy @record.destroy redirect_to @domain, notice: 'Record was successfully destroyed.' end private def set_record @record = @domain.records.find(params[:id]) end def set_domain @domain = Domain.find(params[:domain_id]) end def edit_record_params - params.require(:record).permit(:name, :content, :prio) + params.require(:record).permit(:name, :content, :prio, :disabled) end def new_record_params params.require(:record).permit(:name, :content, :type, :prio) end end diff --git a/app/views/domains/show.html.erb b/app/views/domains/show.html.erb index 42a3499..492b698 100644 --- a/app/views/domains/show.html.erb +++ b/app/views/domains/show.html.erb @@ -1,24 +1,31 @@ - + <% @domain.records.each do |record| %> - + + <% end %>
RecordsControlsControls
<%= record.name %> IN <%= record.type %> <%= record.supports_prio? ? record.prio : '' %> <%= record.content %> + <% if record.disabled? %> + <%= link_to 'Enable', enable_domain_record_path(@domain, record), method: :put %> + <% else %> + <%= link_to 'Disable', disable_domain_record_path(@domain, record), method: :put %> + <% end %> + <%= link_to 'Edit', edit_domain_record_path(@domain, record) %> <%= link_to 'Remove', [@domain, record], method: :delete, data: { confirm: 'Are you sure?' } %>

<%= link_to 'New Record', new_domain_record_path(@domain) %>

diff --git a/config/routes.rb b/config/routes.rb index dfdfd7e..bcf2ad8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,16 @@ Rails.application.routes.draw do get '/', to: redirect('/domains') resources :domains do - resources :records, except: [:index, :show] + resources :records, except: [:index, :show] do + # Reuse records#update instead of introducing new controller actions + # + # rubocop:disable Style/AlignHash + put :disable, to: 'records#update', on: :member, + defaults: { record: { disabled: true } } + put :enable, to: 'records#update', on: :member, + defaults: { record: { disabled: false } } + # rubocop:enable Style/AlignHash + end end end