It appears as if you are doing a, ruby on rails form with javascript validations. While you can do that, I would recommend starting with a basic MVC structure. I highly recommend running through a some basics that will orient you to this. http://guides.rails.info/ is a great place to start. I wish that it had been there when I got started, it would have saved me a great deal of pain :)
The you will want to move your validations into the model.
in app/models/question.rb
class Question < ActiveRecord::Base
validates_presence_of :question
end
more baked in validation options here.
then you want to have a controller to respond to your create events. in app/controller/question_controller.rb
:
class QuestionsController < ApplicationController
def new
@question = Question.new
end
def create
@question = Question.new(params[:question])
if @question.save
flash[:confirm] = "You have asked a question"
redirect_to questions_path
else
flash[:error] = @question.errors.full_messages.join(",")
render :action => :new
end
end
end
And then your config/routes.rb
map.resources :questions
Your form should look similar to what you have:
<%= flash[:error] %>
<% form_for(@question) do |f| %>
<%= f.text_field :content ...
<% end %>
the flash is crude, I haven't used it in a while. I use the message_block plugin. You can also read more about how the flash works here
There are plugins to shorten some of this, but I recommend cutting your teeth my doing some of this first. It helps you get oriented. Best of luck!