parent
120b53300e
commit
5b9e24dcf3
@ -1,10 +1,52 @@ |
||||
class SitesController < ApplicationController |
||||
before_action :set_group, only: [:edit, :update, :destroy] |
||||
before_action :set_site, only: %i[show edit update destroy] |
||||
|
||||
def index |
||||
@sites = Site.all.includes(:group).order(:group_id, :url) |
||||
end |
||||
|
||||
def show |
||||
@site = Site.find params[:id] |
||||
end |
||||
|
||||
def new |
||||
@site = Site.new |
||||
end |
||||
|
||||
def create |
||||
@site = Site.new(site_params) |
||||
if @site.save |
||||
redirect_to config_index_path, notice: 'Site has been successfully created.' |
||||
else |
||||
render :new |
||||
end |
||||
end |
||||
|
||||
def edit |
||||
end |
||||
|
||||
def update |
||||
if @site.update(site_params) |
||||
redirect_to config_index_path, notice: 'Site has been successfully updated.' |
||||
else |
||||
render :edit |
||||
end |
||||
end |
||||
|
||||
|
||||
def destroy |
||||
@site.destroy |
||||
redirect_to config_index_path, notice: 'Site has been successfully removed.' |
||||
end |
||||
|
||||
private |
||||
def set_site |
||||
@site = Site.find params[:id] |
||||
end |
||||
|
||||
def site_params |
||||
params.require(:site).permit( |
||||
:id, :name, :url, :template_id, :group_id, |
||||
targets_attributes: %i[id name css from to site_id _destroy] |
||||
) |
||||
end |
||||
end |
||||
|
@ -0,0 +1,44 @@ |
||||
<%= form_with(model: site, local: true, remote: true, class: "mts") do |form| %> |
||||
<% if site.errors.any? %> |
||||
<div id="alert--error"> |
||||
<h2><%= pluralize(site.errors.count, "error") %> prohibited this site from being saved:</h2> |
||||
|
||||
<ul> |
||||
<% site.errors.full_messages.each do |message| %> |
||||
<li><%= message %></li> |
||||
<% end %> |
||||
</ul> |
||||
</div> |
||||
<% end %> |
||||
|
||||
<fieldset class="mbs pas block"> |
||||
<legend class="h4-like"><%= :site %></legend> |
||||
<div class="auto-grid has-gutter mbs"> |
||||
<%= form.label :name, :name, class: 'txtright' %>: |
||||
<%= form.text_field :name %> |
||||
|
||||
<%= form.label :url, :url, class: 'txtright' %>: |
||||
<%= form.url_field :url %> |
||||
|
||||
<%= form.label :template_id, :template_id, class: 'txtright' %> |
||||
<%= form.select :template_id, |
||||
::Template.all.collect {|t| [t.name, t.id]}, |
||||
{include_blank: true}, |
||||
{prompt: 'Select template'} %> |
||||
</div> |
||||
</fieldset> |
||||
|
||||
<fieldset class="mbs pas block"> |
||||
<legend class="h4-like"><%= :targets %></legend> |
||||
<%= form.fields_for :targets do |builder| %> |
||||
<%= render 'target_fields', f: builder %> |
||||
<% end %> |
||||
|
||||
<%= link_to_add_fields :add_target, form, :targets %> |
||||
</fieldset> |
||||
|
||||
<div class="actions"> |
||||
<%= form.submit :submit %> |
||||
</div> |
||||
|
||||
<% end %> |
@ -0,0 +1,19 @@ |
||||
<fieldset class="pan mbs"> |
||||
<div class="auto-grid has-gutter"> |
||||
<%= f.label :name, :name %>: |
||||
<%= f.text_field :name %> |
||||
|
||||
<%= f.label :css, :css %>: |
||||
<%= f.text_field :css %> |
||||
|
||||
<%= f.label :from, :from %>: |
||||
<%= f.text_field :from %> |
||||
|
||||
<%= f.label :to, :to %>: |
||||
<%= f.text_field :to %> |
||||
|
||||
<%= f.hidden_field :_destroy %> |
||||
<%= link_to :delete, "#", class: "remove_fields" %> |
||||
|
||||
</div> |
||||
</fieldset> |
@ -0,0 +1,5 @@ |
||||
<h1 class="txtcenter"><%= :edit %> <%= @site.name %></h1> |
||||
|
||||
<%= render 'form', site: @site %> |
||||
|
||||
<%= link_to :back, config_index_path %> |
@ -0,0 +1,5 @@ |
||||
<h1 class="txtcenter"><%= t(:new_site) %></h1> |
||||
|
||||
<%= render 'form', site: @site %> |
||||
|
||||
<%= link_to :back, config_index_path %> |
Loading…
Reference in new issue