Browse files

Render blog post on create page

To get the blog post content rendered in the view, we attempt to create a new BlogPost instance with the passed-in form params.

We don't yet attempt to save it to the database because the acceptance test hasn't led us there yet. All it's said is that we need an object on the `create` page that responds to a `title` method (and a `body` method). That doesn't require us to save anything to the database: all that requires is us instantiating an object.

Outer red: ActiveModel::ForbiddenAttributesError

Attempting to instantiate a BlogPost leads to a new error: Rails' "strong parameters" security feature means that we can't just pass user-submitted params directly into a model; that could result in users hacking our system by setting fields they shouldn't be able to, like the user a post belongs to.
  • Loading branch information...
CodingItWrong committed Feb 26, 2016
1 parent f1f3772 commit edfcb21d7b7028517adc000cc246a6646ccfcde7
Showing with 6 additions and 1 deletion.
  1. +1 −0 app/controllers/blog_posts_controller.rb
  2. +5 −1 app/views/blog_posts/create.html.erb
@@ -4,5 +4,6 @@ def new
def create
@blog_post =[:blog_post])
@@ -1 +1,5 @@
<%# empty view %>
<h1><%= @blog_post.title %></h1>
<%= @blog_post.body %>

0 comments on commit edfcb21

Please sign in to comment.