Been Facing this issue,I Have as my view
<%= form_for(:pin, :url => {:action =>"fees"}) do |f| %>
<%= f.text_field :pin_no %>
<%= f.submit "Check Pin" , :class => "new_button round" %>
<% end %>
and in my controller i have
def fees
@title = "Pay Fees"
pin = Pin.check_pin(params[:pin][:pin_no])
if pin.nil?
flash.now[:error] = "Pin is not Avaliable"
render 'fees'
else
flash.now[:success] = "Pin Avaliable"
end
end
in my model, i have a check_pin method defined thus
def check_pin(pin_to_check)
pin = find_by_pin_no(pin_to_check)
if pin.nil?
nil
else
pin
end
end
and i always have this error
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
what am i missing here please?
You get
params[:pin][:pin_no]only when you post the form so it is giving errornil.[]so addrequest.post?to check it only when form is post