Commit b35ac46c authored by Chrysanthi Lagodimou's avatar Chrysanthi Lagodimou
Browse files

scaffold and view form new

parent 4655c6f5
class VolunteersController < ApplicationController
before_action :set_volunteer, only: [:show, :edit, :update, :destroy]
def index
@volunteers = Volunteer.all
end
def show; end
def new
@volunteer = Volunteer.new
end
def edit; end
def create
@volunteer = Volunteer.new(volunteer_params)
respond_to do |format|
if @volunteer.save
format.html { redirect_to @volunteer, notice: 'Volunteer was successfully created.' }
format.json { render :show, status: :created, location: @volunteer }
else
format.html { render :new }
format.json { render json: @volunteer.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @volunteer.update(volunteer_params)
format.html { redirect_to @volunteer, notice: 'Volunteer was successfully updated.' }
format.json { render :show, status: :ok, location: @volunteer }
else
format.html { render :edit }
format.json { render json: @volunteer.errors, status: :unprocessable_entity }
end
end
end
def destroy
@volunteer.destroy
respond_to do |format|
format.html { redirect_to volunteers_url, notice: 'Volunteer was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_volunteer
@volunteer = Volunteer.find(params[:id])
end
def volunteer_params
params.require(:volunteer).permit(:first_name, :last_name, :date_of_birth, :gender,
:address, :nationality, :dual_nationality, :email, :phone, :profession, :education,
:motivation, :experience, :expectations, :strengths, :skills, :interests, :state,
:duration, :man, :woman, :family, :kid, :sport, :creative, :music, :culture, :training,
:german_course, :adults, :teenagers, :children, :city, :region, :canton)
end
end
class Volunteer < ApplicationRecord
end
= simple_form_for(@volunteer) do |f|
- if f.error_notification.present?
.row
.col-xs-12
= f.error_notification
.row
.col-xs-12.col-md-6
= f.input :first_name
.col-xs-12.col-md-6
= f.input :last_name
.row
.col-xs-12.col-md-6
= f.input :date_of_birth, as: :date, start_year: Date.today.year - 90,
end_year: Date.today.year, order: [:day, :month, :year], include_blank: true
.col-xs-12.col-md-6
= f.input :gender, collection: gender_collection, as: :radio_buttons
.row
.col-xs-12.col-md-6
= f.input :nationality, collection: countries
.col-xs-12.col-md-6
= f.input :dual_nationality, collection: countries
.row
.col-xs-12
= f.input :address
.col-xs-12.col-md-6
= f.input :email
.col-xs-12.col-md-6
= f.input :phone
.row
.col-xs-12
= f.input :profession
= f.input :education
= f.input :motivation
= f.input :experience
= f.input :expectations
= f.input :strengths
= f.input :skills
= f.input :interests
.row
.col-xs-12
= f.input :state
.row
.col-xs-12
= f.input :duration, collection: ['short', 'long'], as: :radio_buttons
.row
.col-xs-12.col-md-1
= f.input :man
.col-xs-12.col-md-1
= f.input :woman
.col-xs-12.col-md-1
= f.input :family
.col-xs-12.col-md-1
= f.input :kid
.row
.col-xs-12.col-md-1
= f.input :sport
.col-xs-12.col-md-1
= f.input :creative
.col-xs-12.col-md-1
= f.input :music
.col-xs-12.col-md-1
= f.input :culture
.col-xs-12.col-md-1
= f.input :training
.col-xs-12.col-md-1
= f.input :german_course
.row
.col-xs-12.col-md-1
= f.input :adults
.col-xs-12.col-md-1
= f.input :teenagers
.col-xs-12.col-md-1
= f.input :children
.row
.col-xs-12
= f.input :region, collection: ['city', 'region', 'canton'], as: :radio_buttons
.row
.col-xs-12
= f.button :submit, class: 'btn btn-success'
h1 Editing volunteer
== render 'form'
= link_to 'Show', @volunteer
' |
= link_to 'Back', volunteers_path
h1 Listing volunteers
table
thead
tr
th First name
th Last name
th
th
th
tbody
- @volunteers.each do |volunteer|
tr
td = volunteer.first_name
td = volunteer.last_name
td = link_to 'Show', volunteer
td = link_to 'Edit', edit_volunteer_path(volunteer)
td = link_to 'Destroy', volunteer, data: { confirm: 'Are you sure?' }, method: :delete
br
= link_to 'New Volunteer', new_volunteer_path
h1 New volunteer
== render 'form'
= link_to 'Back', volunteers_path
p#notice = notice
p
strong First name:
= @volunteer.first_name
p
strong Last name:
= @volunteer.last_name
= link_to 'Edit', edit_volunteer_path(@volunteer)
' |
= link_to 'Back', volunteers_path
Rails.application.routes.draw do
resources :volunteers
devise_for :users
resources :users
......
class CreateVolunteers < ActiveRecord::Migration[5.1]
def change
create_table :volunteers do |t|
t.string :first_name
t.string :last_name
t.date :date_of_birth
t.string :gender
t.text :address
t.string :nationality
t.string :dual_nationality
t.string :email
t.string :phone
t.string :profession
t.text :education
t.text :motivation
t.boolean :experience
t.text :expectations
t.text :strengths
t.text :skills
t.text :interests
t.string :state, default: 'interested/registered'
t.string :duration
t.boolean :man
t.boolean :woman
t.boolean :family
t.boolean :kid
t.boolean :sport
t.boolean :creative
t.boolean :music
t.boolean :culture
t.boolean :training
t.boolean :german_course
t.boolean :adults
t.boolean :teenagers
t.boolean :children
t.boolean :city
t.string :region
t.timestamps
end
end
end
......@@ -129,6 +129,45 @@ ActiveRecord::Schema.define(version: 20170511135554) do
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
create_table "volunteers", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.date "date_of_birth"
t.string "gender"
t.text "address"
t.string "nationality"
t.string "dual_nationality"
t.string "email"
t.string "phone"
t.string "profession"
t.text "education"
t.text "motivation"
t.boolean "experience"
t.text "expectations"
t.text "strengths"
t.text "skills"
t.text "interests"
t.string "state", default: "interested/registered"
t.string "duration"
t.boolean "man"
t.boolean "woman"
t.boolean "family"
t.boolean "kid"
t.boolean "sport"
t.boolean "creative"
t.boolean "music"
t.boolean "culture"
t.boolean "training"
t.boolean "german_course"
t.boolean "adults"
t.boolean "teenagers"
t.boolean "children"
t.boolean "city"
t.string "region"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_foreign_key "clients", "users"
add_foreign_key "language_skills", "clients"
add_foreign_key "profiles", "users"
......
FactoryGirl.define do
factory :volunteer do
first_name 'Volunteer'
last_name 'Volunteer'
end
end
require 'test_helper'
class VolunteerTest < ActiveSupport::TestCase
end
require 'application_system_test_case'
class VolunteersTest < ApplicationSystemTestCase
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment