Activity
Is is possible to host multiple sites on a droplet with this setup?
I had to cd into myapp/current then run RAILS_ENV=production bundle exec rails c
I figured it out. I had to cd into myapp/current then run RAILS_ENV=production bundle exec rails c
Great tutorial. I got everything working but can you tell me how I can access the rails console from the server?
Thanks for the episode. Trix is easy and works great but is there a way to style the images. I managed to get them to align left or right but cannot get them to float left or right with text around them.
I have a registration form that allows tournament directors to select which fields they will request when participants register for a tournament. I followed a video to add dynamic nested form fields into a form using stimulus JS and it works great.
I am trying to add a second group of fields in another section fo the form. the form is broken into section, basic info, contact info, competition info, etc and I would like to have the ability to add custom fields to each section.
In the basic section it works great. I can add and remove custom fields, but when I added it to the contact section, even with change nested-form to nested-contacts, it just puls in the fields I create in the basic section. I can add and remvoe from either section but it just shows them all in both sections.
Here is my form as it is now. I still have to add the other sections but was trying to get basic and contact custom fields working before adding the rest of the form:
<h4>Athlete Information</h4>
<%= form_with(model: @event, class: "shadow p-3 mb-3 rounded text-dark", local: true) do |f| %>
<%= f.hidden_field :athlete_info_complete, value: 1 %>
<%= f.hidden_field :next, value: 6 %>
<div class="row club_container">
<div class="col-12">
<legend>
Check all the boxes next to the information you would like to
request from your tournament participants. Each area will have an option
to add custom fields.
</legend>
<br><br>
<h4>Basic Information</h4>
<div class="form-group row">
<div class="col-md-9 col-sm-12">
<label class="main">First Name
<%= f.check_box :first_name %>
<span class="w3docs"></span>
</label>
<label class="main">Last Name
<%= f.check_box :last_name %>
<span class="w3docs"></span>
</label>
<label class="main">Date of birth
<%= f.check_box :dob %>
<span class="w3docs"></span>
</label>
</div>
</div>
<h4>Custom Fields</h4>
<small>
Enter the name of your custom field you plan to offer.
</small>
<br><br>
<div data-controller="nested-form">
<template data-target="nested-form.template">
<%= f.fields_for :fields, Field.new, child_index: 'NEW_RECORD' do |field| %>
<%= render 'events/forms/custom_fields_basic', f: field %>
<% end %>
</template>
<%= f.fields_for :fields do |field| %>
<%= render 'events/forms/custom_fields_basic', f: field %>
<% end %>
<div class="mb-3" data-target="nested-form.links">
<%= link_to 'Add Custom Field', "#", class: "btn btn-outline-dark", data: { action: "click->nested-form#add_association" } %>
</div>
</div>
<h4>Contact Information</h4>
<div class="form-group row">
<div class="col-md-9 col-sm-12">
<label class="main">Address 1
<%= f.check_box :address1 %>
<span class="w3docs"></span>
</label>
<label class="main">Address 2
<%= f.check_box :address2 %>
<span class="w3docs"></span>
</label>
<label class="main">City
<%= f.check_box :city %>
<span class="w3docs"></span>
</label>
</div>
</div>
<div data-controller="nested-contacts">
<template data-target="nested-contacts.template">
<%= f.fields_for :fields, Field.new, child_index: 'NEW_RECORD' do |field| %>
<%= render 'events/forms/custom_fields_contact', f: field %>
<% end %>
</template>
<%= f.fields_for :fields do |field| %>
<%= render 'events/forms/custom_fields_contact', f: field %>
<% end %>
<div class="mb-3" data-target="nested-contacts.links">
<%= link_to 'Add Custom Field', "#", class: "btn btn-outline-dark", data: { action: "click->nested-contacts#add_association" } %>
</div>
</div>
<div class="form-group row">
<div class="col-md-9 col-sm-12"></div>
<div class="col-md-3 col-sm-12">
<button id="button_next" class="profile_btn align-middle" style="width:180px;">Finalize <span style="margin-top: 5px; font-size: 18px;"><i class="fas fa-long-arrow-alt-right"></i></span></button>
</div>
</div>
</div>
</div>
<% end %>
Here is the _custom_fields_basic.html.erb
<%= content_tag :div, class: 'nested-fields', data: { new_record: f.object.new_record? } do %>
<div class="form-group row">
<div class="col-md-3 col-sm-12 col-form-label">
<%= f.label :field_name %>
</div>
<div class="col-md-9 col-sm-12">
<%= f.text_field :name, class: 'form-control' %>
<small><%= link_to 'Remove', '#', data: { action: 'click->nested-form#remove_association' } %></small>
</div>
</div>
<%= f.hidden_field :field_type, value: 'basic' %>
<%= f.hidden_field :_destroy %>
<% end %>
This is the custom_fields_contact.html.erb file:
<%= content_tag :div, class: 'nested-contacts', data: { new_record: f.object.new_record? } do %>
<div class="form-group row">
<div class="col-md-3 col-sm-12 col-form-label">
<%= f.label :field_name %>
</div>
<div class="col-md-9 col-sm-12">
<%= f.text_field :name, class: 'form-control' %>
<small><%= link_to 'Remove', '#', data: { action: 'click->nested-contacts#remove_association' } %></small>
</div>
</div>
<%= f.hidden_field :field_type, value: 'contact' %>
<%= f.hidden_field :_destroy %>
<% end %>
Here is the nexted_form_controller.js
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ "links", "template" ]
connect() {
}
add_association(event) {
event.preventDefault()
var content = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, new Date().getTime())
this.linksTarget.insertAdjacentHTML('beforebegin', content)
}
remove_association(event) {
event.preventDefault()
let wrapper = event.target.closest(".nested-fields")
if (wrapper.dataset.newRecord == "true") {
wrapper.remove()
} else {
wrapper.querySelector("input[name*='_destroy']").value = 1
wrapper.style.display = 'none'
}
}
}
And the nested_contacts_controller.js:
import { Controller } from "stimulus"
export default class extends Controller {
static targets = [ "links", "template" ]
connect() {
}
add_association(event) {
event.preventDefault()
var content = this.templateTarget.innerHTML.replace(/NEW_RECORD/g, new Date().getTime())
this.linksTarget.insertAdjacentHTML('beforebegin', content)
}
remove_association(event) {
event.preventDefault()
let wrapper = event.target.closest(".nested-contacts")
if (wrapper.dataset.newRecord == "true") {
wrapper.remove()
} else {
wrapper.querySelector("input[name*='_destroy']").value = 1
wrapper.style.display = 'none'
}
}
}
If there is way to do it with a single controller that would be great, but I'm ok with having separate controllers for each section if necessary.
Thanks
That was fantastic. Thank you so much. I was pulling my hear out trying to make this work but this was a snap. One question Ihave is how would yu emplement this a second time within the same form?
Thanks for the tutorial. I've been trying for a while to fiture out how to setup a server to deploy rails apps. I followed the video and everything went well but when I try to deploy I get the following error: I have search all over and posted on stackoverflow.com but can't get any answer. Any help would be greatly appreciated. I will say that I did use ubuntu 20, so if that is the issue I am willing to scrp the whole thig and do it again using 18.4 instead.
terminated with exception (report_on_exception is true):
Traceback (most recent call last):
25: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:12:in block (2 levels) in execute'
run'
24: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:31:in
23: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:31:in instance_exec'
block (3 levels) in '
22: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/capistrano-rbenv-2.2.0/lib/capistrano/tasks/rbenv.rake:10:in
21: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:61:in test'
create_command_and_execute'
20: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in
19: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in tap'
block in create_command_and_execute'
18: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in
17: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/netssh.rb:130:in execute_command'
with_ssh'
16: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/netssh.rb:177:in
15: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/connection_pool.rb:63:in with'
call'
14: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/connection_pool.rb:63:in
13: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh.rb:255:in start'
authenticate'
12: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/session.rb:72:in
11: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/session.rb:72:in each'
block in authenticate'
10: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/session.rb:86:in
9: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/methods/publickey.rb:19:in authenticate'
each_identity'
8: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/key_manager.rb:111:in
7: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/key_manager.rb:250:in load_identities'
map'
6: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/key_manager.rb:250:in
5: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/key_manager.rb:254:in block in load_identities'
load_public_key'
4: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/key_factory.rb:84:in
3: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/key_factory.rb:103:in load_data_public_key'
read_key'
2: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/buffer.rb:248:in
1: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/buffer.rb:322:in
read_keyblob'
raiseUnlessLoaded': unsupported key type `ssh-ed25519' (NotImplementedError)
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/ed25519_loader.rb:21:in
net-ssh requires the following gems for ed25519 support:
- ed25519 (>= 1.2, < 2.0)
- bcrypt_pbkdf (>= 1.0, < 2.0) See https://github.com/net-ssh/net-ssh/issues/565 for more information LoadError : "cannot load such file -- bcrypt_pbkdf_ext" (Backtrace restricted to imported tasks) cap aborted! NotImplementedError: unsupported key type `ssh-ed25519' net-ssh requires the following gems for ed25519 support:
- ed25519 (>= 1.2, < 2.0)
- bcrypt_pbkdf (>= 1.0, < 2.0) See https://github.com/net-ssh/net-ssh/issues/565 for more information LoadError : "cannot load such file -- bcrypt_pbkdf_ext"
Tasks: TOP => rbenv:validate
Thanks,
Scott