Commit 670ee722 authored by Bianca Tarun's avatar Bianca Tarun

fixed position simple form

parent ca6be502
class CandidatesController < ApplicationController
def index
@candidates = Candidates.all
end
end
\ No newline at end of file
class PositionsController < ApplicationController
before_action :authenticate_user!
def show
@position = Position.find(params[:id])
@candidates = @position.candidates
render "positions/show.html.erb"
end
end
\ No newline at end of file
class View < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<%= f.input :first_name %> <%= f.input :first_name %>
<%= f.input :last_name %> <%= f.input :last_name %>
<%= f.input :nickname %> <%= f.input :nickname %>
<%= f.association :position %>
<%= f.input :slogan %> <%= f.input :slogan %>
<%= f.submit %> <%= f.submit %>
<% end %> <% end %>
\ No newline at end of file
...@@ -2,26 +2,9 @@ ...@@ -2,26 +2,9 @@
<hr> <hr>
<%= link_to("New Candidate", new_admin_candidate_path) %> <%= link_to("New Candidate", new_admin_candidate_path) %>
<hr> <hr>
<table width="100%"> <% @positions.each do |position| %>
<tr> <h2><%= @position.name %></h2>
<th>First Name</th> <% end %>
<th>Last Name</th> <hr>
<th>Nickname</th>
<th>Slogan</th>
<th>Actions</th>
</tr>
<% @candidates.each do |candidate| %>
<tr>
<td><%= candidate.first_name %></td>
<td><%= candidate.last_name %></td>
<td><%= candidate.nickname %></td>
<td><%= candidate.slogan %></td>
<td>
<%= link_to "Show", admin_candidate_path(candidate.id) %>
<%= link_to "Edit", edit_admin_candidate_path(candidate.id) %>
<%= link_to "Delete", admin_candidate_path(candidate.id), method: :delete, data: { confirm: 'Are you sure?' } %>
</td>
</tr>
<% end %>
</table>
Rails.application.routes.draw do Rails.application.routes.draw do
devise_for :views
devise_for :users devise_for :users
namespace :admin do namespace :admin do
resources :positions resources :positions
resources :candidates resources :candidates
end end
resources :candidates
resources :positions resources :positions
resources :candidates resources :votes
root to: "pages#index" root to: "pages#index"
end end
class DeviseCreateViews < ActiveRecord::Migration
def change
create_table :views do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :views, :email, unique: true
add_index :views, :reset_password_token, unique: true
# add_index :views, :confirmation_token, unique: true
# add_index :views, :unlock_token, unique: true
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160718031721) do ActiveRecord::Schema.define(version: 20160720021955) do
create_table "candidates", force: :cascade do |t| create_table "candidates", force: :cascade do |t|
t.string "first_name" t.string "first_name"
...@@ -50,6 +50,24 @@ ActiveRecord::Schema.define(version: 20160718031721) do ...@@ -50,6 +50,24 @@ ActiveRecord::Schema.define(version: 20160718031721) do
add_index "users", ["email"], name: "index_users_on_email", unique: true add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
create_table "views", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "views", ["email"], name: "index_views_on_email", unique: true
add_index "views", ["reset_password_token"], name: "index_views_on_reset_password_token", unique: true
create_table "votes", force: :cascade do |t| create_table "votes", force: :cascade do |t|
t.text "comments" t.text "comments"
t.datetime "created_at", null: false t.datetime "created_at", null: false
......
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
require 'test_helper'
class ViewTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Markdown is supported
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