I'm a bit confused about the purpose of remote:true in Rails forms. I initially thought that it required some Javascript to enable asynchronous functionality, but instead it seems to be causing issues with my page.
Below is a simple index.html.haml file that includes a partial for displaying all appointments:
%h1 Calendar
%h2 AppointmentsController
%h3 Make a new appointment
= form_for @appointment, remote: true do |f|
= f.text_field :title
= f.text_field :appt_time
= f.submit 'Make appointment'
#appointments
=render 'appointments'
Here's the mentioned partial:
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f8d5b89988889791968c959d968c8bd69d999b90">[email protected]</a> do |a|
%h3= a.title
%p= a.appt_time
Controller methods for index and create:
def index
@appointments = Appointment.order('appt_time ASC')
@appointment = Appointment.new
end
def create
@appointmet = Appointment.create(appointment_params)
redirect_to :root
end
So far everything seems to be working correctly. I can add a new appointment, submit the form, and see the new appointment appear without the page refreshing, thanks to the inclusion of remote: true
. However, I'm wondering if there are any additional steps needed to handle this request properly or if relying solely on remote: true is sufficient. Am I potentially not following best practices by omitting additional handling for this request?