Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
suggest me a step-by-step procedure for form creation
2 Posts
suggest me a step-by-step procedure for form creation

Good Day Wishes .

I am the beginner for RoR. I tried a lot but unable to capture the whole of the “FORM” and its usage. Kindly give me a step-by-step procedure to learn how forms work?

suggest a sample example ?

Thank you in advance.

Hello There,

I'll try to explain how forms work in a few steps, so here we go:

  • to start you need to put a form_for tag in your view (for example we're going to make a blog app)

So piece by piece - form_for -> creates an html form tag - @post is the collection where all your data will be put in - do |p| -> that we will see later - end -> we need to close the form tag

Between the form tags you can place for example a text_field like this :

  • p -> is an instance of the db field
  • submit -> this creates a submit button for submitting your data

Your controller could look like this :

def new

 @post = Post.new

end -> here you create an instance that you'll use in your form def create

 @post = Post.new(params[:post]) -> We create a new post entry with all the data of our form
 if @post.save and request.post? -> "security" check
   flash[:notice] = "This post is created"
   redirect_to posts_path
   render :action => 'new' -> else show the form again


If you're still having question, just fire away:)

2 Posts
Login to add your message