Open duleorlovic opened 1 year ago
@duleorlovic Can you please provide me with model to use in form
I think you can use Form object, just plain ruby class with include ActiveModel::Model
eg https://github.com/duleorlovic/rails_helpers_and_const/blob/main/app/forms/registration_form.rb
@Orlovic982 please use existing Pages controller instead of creating new one.
# app/forms/contact_form.rb
class ContactForm
include ActiveModel::Model
FIELDS = %i[name email question]
attr_accessor *FIELDS
validates *FIELDS, presence: true
def save
return false unless valid?
# here you can send the email
true
end
end
# config/routes.rb
get 'contact', to: 'pages#contact'
post 'contact', to: 'pages#submit_contact'
# app/controllers/pages_controller.rb
def contact
@contact_form = ContactForm.new(
email: current_user&.email
)
end
def submit_contact
@contact_form = ContactForm.new _contact_form_params
if @contact_form.save
flash.now[:notice] = t('contact_thanks')
contact
else
flash.now[:alert] = @contact_form.errors.full_messages.join(', ')
end
render :contact
end
def _contact_form_params
params.require(:contact_form).permit(
*ContactForm::FIELDS,
)
end
# app/views/pages/contact.html.erb
<%= bootstrap_form_for @contact_form, url: contact_path do |f| %>
<%= f.email_field :email, required: true, disabled: current_user.present? %>
Hello @Orlovic982, can I work on this task, please?
Yes,of course. I dont have much time at the moment, but I will catch you guys later
https://github.com/trkin/kindergarten-exchange/pull/41 All required changes are made. @ more Pull requests are waiting for review.
@vesnalesevic can you work on contact form ? You can learn about Form objects on https://openai.com/blog/openai-api
This form should be public. It requires: name (string), email (string) (populated if it is already logged in) and question (text) field. Write a test that the email is sent.