added admin

parent 48197d5d
module Admin
class CandidatesController < ApplicationController
def index
@positions = Position.all
render "admin/candidates/index.html.erb"
end
def new
@candidate = Candidate.new
render "admin/candidates/new.html.erb"
end
def edit
@candidate = Candidate.find(params[:id])
end
def update
@candidate = Candidate.find(params[:id])
if @candidate.update(candidate_params())
redirect_to admin_candidates_path(@candidate.id)
else
render "admin/candidates/edit.html.erb"
end
end
def destroy
@candidate = Candidate.find(params[:id])
@candidate.destroy!
redirect_to admin_candidates_path
end
def create
@candidate = Candidate.new(candidate_params())
if @candidate.save
redirect_to admin_candidate_path(@candidate.id)
else
render "admin/candidates/new.html.erb"
end
end
def show
@candidate = Candidate.find(params[:id])
render "admin/candidates/show.html.erb"
end
def candidate_params
params.require(:candidate).permit!
end
end
end
\ No newline at end of file
module Admin
class PositionsController < ApplicationController
def index
@positions = Position.all
render "admin/positions/index.html.erb"
end
def new
@position = Position.new
render "admin/positions/new.html.erb"
end
def edit
@position = Position.find(params[:id])
end
def update
@position = Position.find(params[:id])
if @position.update(position_params())
redirect_to admin_positions_path(@position.id)
else
render "admin/position/edit.html.erb"
end
end
def destroy
@candidate = Position.find(params[:id])
@candidate.destroy!
redirect_to admin_positions_path
end
def create
@position = Position.new(position_params())
if @position.save
redirect_to admin_position_path(@position.id)
else
render "admin/positions/new.html.erb"
end
end
def show
@position = Position.find(params[:id])
render "admin/positions/show.html.erb"
end
def position_params
params.require(:position).permit!
end
end
end
<%= simple_form_for([:admin, @candidate]) do |f| %>
I wanna vote for
<%= f.association :position, label_method: :name, value_method: :id %>
<%= f.input :first_name%>
<%= f.input :last_name%>
<%= f.input :slogan%>
<%= f.submit %>
<% end %>
<h1>Admin Edit Post</h1>
<%= render partial: "form" %>
<%= link_to "Back to Candidates", admin_candidates_path %>
\ No newline at end of file
<h4>Displaying All Candidates Grouped By Positions </h4>
<%=link_to "+ new Candidate", new_admin_candidate_path%>
<div class="container">
<% @positions.each do |p| %>
<div style="display:inline-block; border:solid 1px; padding:40px; bottom:0; width:140px; margin:20px;">
<h5> <%= p.name %></h5>
<ul >
<% p.candidates.each do |c|%>
<li><%=link_to c.full_name, admin_candidate_path(c.id)%></li>
<% end %>
</ul>
</div>
<% end %>
</div>
\ No newline at end of file
<h1>New Candidate</h1>
<%= render partial: "form" %>
<h1 style="margin-bottom:3px;"><%= @candidate.full_name%>
<%=link_to "Edit", edit_admin_candidate_path(@candidate.id), {:style=>"font-size:18px; text-decoration:none; color:rgba(0,0,0,0.5)"}%>
<%=link_to "OBOSEN", admin_candidate_path(@candidate.id), {:style=>"font-size:18px; text-decoration:none; color:rgba(200,0,0,0.5)", method: :delete}%></h1>
<h3 style="margin-top:3px; color:#004e7e"><%= @candidate.position.name %></h3>
<p>
<%= @candidate.slogan%>
</p>
<hr>
<%= link_to "Back to Candidates", admin_candidates_path %>
<%= simple_form_for([:admin, @position]) do |f| %>
<%= f.input :name%>
<%= f.submit %>
<% end %>
<h1>Admin Edit Post</h1>
<%= render partial: "form" %>
<%= link_to "Back to Candidates", admin_candidates_path %>
\ No newline at end of file
<h4>Positions from the Vote-a-Sutra </h4>
<%=link_to "+ new Position", new_admin_position_path%>
<div class="container">
<% @positions.each do |p| %>
<div style="">
<a href="#"> <%= link_to p.name, admin_position_path(p.id) %></a>
</ul>
</div>
<% end %>
</div>
\ No newline at end of file
<h1>New Candidate</h1>
<%= render partial: "form" %>
<h1 style="margin-bottom:3px;"><%= @position.name%>
<%=link_to "Edit", edit_admin_position_path(@position.id), {:style=>"font-size:18px; text-decoration:none; color:rgba(0,0,0,0.5)"}%>
<%=link_to "OBOSEN", admin_position_path(@position.id), {:style=>"font-size:18px; text-decoration:none; color:rgba(200,0,0,0.5)", method: :delete}%></h1>
<%@position.candidates.each do |c|%>
<li><%=link_to c.full_name, admin_candidate_path(c.id)%></li>
<%end%>
<%= link_to "Back to Positions", admin_positions_path %>
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