Ruby on Rails Tutorial Part 6 - CRUD - Create - Save Method

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
1,598
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Sep 20, 2011

In this Ruby on Rails Tutorial we'll learn how to create new posts using using the save method and the form_for method. We'll also learn about redirecting and flash messages. In this video I'm using Rails 3.1 and Ruby 1.9.2 on Linux.

The source code for this video should be available on my site within a few days: http://www.andrews-custom-web-design.com/

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (andrewperk)

  • In all pages i get braces before content that replace placeholder yield, and if there is at least a flash i get also the dump into braces... i.e. before post {} Our blog i.e after save post and redirect to posts page Your post was saved {:notice=>"Your post was saved"} Our Blog First post Content of first post Why does it show me dump for flashes? Thanks in advance.
  • @traendone Check your layout file where we looped through the flash hash. You may have put an equals sign in the ERB tag for the loop statement. You only use the equal sign when outputting, not in the actual loop statement or if/else etc... So you should only have an equal sign where we output the value of the loop. <% flash.each do |key, value| %>

  • @traendone Well youtube won't let me put in the actual code in this comment for some reason, so I tried to use html entities but that still didn't work. The point was to show you how it does not have an equals sign in the loop statement. Look again at the video where we loop through the flash hash in the layout to see it. Hopefully this helped you.

  • How is params[:post] working, you dint pass any parameter from html having :post as its name??

  • @koolestdudenw7 When we pass in the @post object to the form_for helper in our view it uses the name of that object to create a hash. In our case the hash is named post. When we create the form fields for the title and content attributes these values are stored under that post hash as post[title] and post[content]. This post hash is available to us in the params hash under its symbol name :post, like so: params[:post]. It contains the data for title and content from the form.

see all

All Comments (9)

Sign In or Sign Up now to post a comment!
  • Once again, verry helpfull tutorial.

  • @traendone hi got the same problem as you while ago and discover my problem was

    from 

    --redirect_to post_path, :notice => "Your post was save"-- i just added letter "s" on the path that will redirect to the index

    -- redirect_to posts_path, :notice => "Your post was save"--

    just share and not shoving my late answer :)

  • @andrewperk I even know why I put the equals sign there.

    Thanks for the reply, patience, and videos.

  • @andrewperk Thankx a lot, btw Great tutorial :)

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more