trkin / kindergarten-exchange

A small tool used for parents to communicate about movement between kindergartens. Developers meet every Friday at noon CET https://meet.jit.si/kindergarten-exchange
https://premesti-se.trk.in.rs/
2 stars 0 forks source link

Create a contact form #4

Open duleorlovic opened 1 year ago

duleorlovic commented 1 year ago

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.

Orlovic982 commented 1 year ago

@duleorlovic Can you please provide me with model to use in form

duleorlovic commented 1 year ago

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? %>
DeVuDeveloper commented 1 year ago

Hello @Orlovic982, can I work on this task, please?

Orlovic982 commented 1 year ago

Yes,of course. I dont have much time at the moment, but I will catch you guys later

DeVuDeveloper commented 1 year ago

https://github.com/trkin/kindergarten-exchange/pull/41 All required changes are made. @ more Pull requests are waiting for review.

duleorlovic commented 1 year ago

@vesnalesevic can you work on contact form ? You can learn about Form objects on https://openai.com/blog/openai-api