Skip to content

Instantly share code, notes, and snippets.

@sebastjan-hribar
Last active October 28, 2019 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastjan-hribar/76bcd650c01837f67ffb143e3470d839 to your computer and use it in GitHub Desktop.
Save sebastjan-hribar/76bcd650c01837f67ffb143e3470d839 to your computer and use it in GitHub Desktop.
Views
tmsr/apps/godmode/views/contact_persons/edit.rb
module Godmode
module Views
module ContactPersons
class Edit
include Godmode::View
def clients_for_select
clients_select = Hash.new
clients.each do |client|
clients_select[client.name] = client.id
end
clients_select
end
end
end
end
end
tmsr/apps/godmode/views/contact_persons/update.rb
module Godmode
module Views
module ContactPersons
class Update
include Godmode::View
template 'contact_persons/edit'
end
end
end
end
------------------
Templates
tmsr/apps/godmode/templates/contact_persons/edit.html.erb
<%=
form_for :contact_person, routes.contact_persons_path(id: contact_person.id), method: :patch, values: {contact_person: contact_person} do
label "Ime"
text_field :name
label "Priimek"
text_field :surname
label "Delovno mesto"
text_field :position
label "Podjetje"
select :client_id, clients_for_select
label "E-pošta"
text_field :email
label "Telefon"
text_field :phone
submit 'Posodobi'
end
%>
------------------
Controllers
tmsr/apps/godmode/controllers/contact_persons/edit.rb
module Godmode
module Controllers
module ContactPersons
class Edit
include Godmode::Action
expose :contact_person, :clients
def call(params)
@contact_person = ContactPersonRepository.new.find(params[:id])
@clients = ClientRepository.new.all
end
end
end
end
end
tmsr/apps/godmode/controllers/contact_persons/update.rb
module Godmode
module Controllers
module ContactPersons
class Update
include Godmode::Action
params do
required(:id).filled
required(:contact_person).schema do
required(:name).filled(:str?)
required(:surname).filled(:str?)
required(:position).filled(:str?)
required(:email).filled(:str?)
required(:phone).filled(:str?)
required(:client).filled(:int?)
end
end
def call(params)
puts params.inspect
ContactPersonRepository.new.update(params[:id], params[:contact_person])
#redirect_to "/godmode/contact_persons/#{params[:id]}"
end
end
end
end
end
------------------
Routes
resources :clients
resources :contact_persons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment