Separate mods#edit and mods#new into 2 views with a shared partial
parent
90591dbf8d
commit
4f4c0b5097
|
@ -29,7 +29,6 @@ class ModsController < ApplicationController
|
|||
|
||||
def new
|
||||
@mod = Mod.new_for_form(current_user, params[:forum_post_id])
|
||||
render_form
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -37,13 +36,12 @@ class ModsController < ApplicationController
|
|||
if @mod.save
|
||||
redirect_to mod_url(@mod)
|
||||
else
|
||||
render_form
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@mod = Mod.find params[:id]
|
||||
render_form
|
||||
end
|
||||
|
||||
def update
|
||||
|
@ -51,17 +49,12 @@ class ModsController < ApplicationController
|
|||
if @mod.update mod_params
|
||||
redirect_to mod_url(@mod)
|
||||
else
|
||||
render_form
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render_form
|
||||
@existing_authors_names = User.pluck(:name)
|
||||
render :new
|
||||
end
|
||||
|
||||
def mod_params
|
||||
permitted = [
|
||||
:name,
|
||||
|
|
|
@ -167,14 +167,6 @@ class ModDecorator < Draper::Decorator
|
|||
'factoriomods://' + Base64.strict_encode64(json_mod).to_s
|
||||
end
|
||||
|
||||
def form_title
|
||||
if mod.new_record?
|
||||
I18n.t('mods.new.new')
|
||||
else
|
||||
h.raw(I18n.t('mods.new.edit') + ' ' + h.link_to(mod.name, mod))
|
||||
end
|
||||
end
|
||||
|
||||
### Download button
|
||||
###################
|
||||
|
||||
|
|
|
@ -64,4 +64,8 @@ module ModsHelper
|
|||
title
|
||||
end
|
||||
end
|
||||
|
||||
def mods_authors_list
|
||||
@mods_authors_list ||= Author.pluck(:name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
= f.input :slug if can? :set_slug, mod
|
||||
= f.input :categories, as: :categories_select
|
||||
= f.input :owner if can? :set_owner, mod
|
||||
= f.input :authors_list, as: :multi_datalist, collection: @existing_authors_names, placeholder: @existing_authors_names.sample(4).push('etc').join(', ')
|
||||
= f.input :authors_list, as: :multi_datalist, collection: mods_authors_list, placeholder: mods_authors_list.sample(4).push('etc').join(', ')
|
||||
= f.input :github
|
||||
= f.input :official_url
|
||||
= f.input :contact
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
- title t('.title', name: @mod.name)
|
||||
%h1
|
||||
= t('.header')
|
||||
= link_to(@mod.name, @mod)
|
||||
= render partial: 'form', locals: { mod: @mod }
|
|
@ -1,4 +1,3 @@
|
|||
- title @mod.new_record? ? t('.title') : t('.title_edit', name: @mod.name)
|
||||
|
||||
%h1= @mod.decorate.form_title
|
||||
- title t('.title')
|
||||
%h1= t('.header')
|
||||
= render partial: 'form', locals: { mod: @mod }
|
||||
|
|
|
@ -10,10 +10,12 @@ en:
|
|||
|
||||
new:
|
||||
title: Create new mod
|
||||
title_edit: Edit %{name} # We use the same view
|
||||
edit: Edit
|
||||
new: Create new mod
|
||||
|
||||
header: Create new mod
|
||||
|
||||
edit:
|
||||
title: Edit %{name}
|
||||
header: Edit
|
||||
|
||||
form:
|
||||
add_version: Add version
|
||||
|
||||
|
|
Loading…
Reference in New Issue