Charlie Charlie - 9 days ago 6
Ruby Question

SyntaxError in CandidatesController#new, Unknown ruby error

Im working on a website using ruby on rails and Ive come to a problem. I added in some functionality to allow the candidate to upload a file, which can then be downloaded (using an AttachmentUploader). I also used gem 'carrierwave'. I get the following error in the candidateController.

"Z:/railsassignment/student/app/views/candidates/_form.html.erb:71: syntax error, unexpected keyword_ensure, expecting keyword_end Z:/railsassignment/student/app/views/candidates/_form.html.erb:73: syntax error, unexpected end-of-input, expecting keyword_end"

This error refers to the <% end %> on line 69. The only time I altered the candidateController was when I added :attachment to the whitelist after migrating it to the candidate table through the cmd. Any solutions would be greatly appreciated.

Ill upload the candidateController as this is where the error lies and Im unsure what else to add. If you need to see something else Ill be happy to add them to the question.

class CandidatesController < ApplicationController
before_action :set_candidate, only: [:show, :edit, :update, :destroy]

# GET /candidates
# GET /candidates.json
def index
@candidates = Candidate.all
end

# GET /candidates/1
# GET /candidates/1.json
def show
end

# GET /candidates/new
def new
@candidate = Candidate.new
end

# GET /candidates/1/edit
def edit
end

# POST /candidates
# POST /candidates.json
def create
@candidate = Candidate.new(candidate_params)

respond_to do |format|
if @candidate.save
UserMailer.welcome(@candidate).deliver
format.html { redirect_to @candidate, notice: 'Candidate was
successfully created.' }
format.json { render :show, status: :created, location: @candidate }
else
format.html { render :new }
format.json { render json: @candidate.errors, status:
:unprocessable_entity }
end
end
end

# PATCH/PUT /candidates/1
# PATCH/PUT /candidates/1.json
def update
respond_to do |format|
if @candidate.update(candidate_params)
format.html { redirect_to @candidate, notice: 'Candidate was successfully updated.' }
format.json { render :show, status: :ok, location: @candidate }
else
format.html { render :edit }
format.json { render json: @candidate.errors, status:
:unprocessable_entity }
end
end
end

# DELETE /candidates/1
# DELETE /candidates/1.json
def destroy
@candidate.destroy
respond_to do |format|
format.html { redirect_to candidates_url, notice: 'Candidate was
successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_candidate
@candidate = Candidate.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def candidate_params
params.require(:candidate).permit(:can_name, :can_surname, :dob, :college, :college_year, :phone_num, :can_email, :address, :experience, :password, :password_confirmation, :attachment)
end
end


candidates/_form

<%= form_for(@candidate) do |f| %>
<% if @candidate.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@candidate.errors.count, "error") %> prohibited this
candidate from being saved:</h2>

<ul>
<% @candidate.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :First_name %><br>
<%= f.text_field :can_name %>
</div>
<div class="field">
<%= f.label :Surname %><br>
<%= f.text_field :can_surname %>
</div>
<div class="field">
<%= f.label :dob %><br>
<%= f.date_field :dob %>
</div>

<div class="field">
<%= f.label :College %><br>
<%= f.text_field :college %>
</div>

<div class="field">
<%= f.label :College_Year %><br>
<%= f.select :college_year, ["1", "2","3","4"]%>
</div>

<div class="field">
<%= f.label :Phone_Number %><br>
<%= f.number_field :phone_num %>
</div>
<div class="field">
<%= f.label :email %><br>
<%= f.text_field :can_email %>
</div>
<div class="field">
<%= f.label :Address %><br>
<%= f.text_field :address %>
</div>
<div class="field">
<%= f.label :Experience %><br>
<%= f.text_area :experience %>
</div>
<div class="field">
<%= f.label :password %><br>
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br>
<%= f.password_field :password_confirmation %>
</div>

<%=form_for @candidate do |f|%>
<%=f.label :attachment %>
<%=f.file_field :attachment %>

<div class="actions">
<%= f.submit %>
</div>
<% end %>

Answer

You forgot to close your first form before you open the second one.