js225
js225

Reputation: 3

Strong params not working in Rails 4.1.7?

*I've tried adding config.action_controller.action_on_unpermitted_parameters = :raise to my development environment already.

*I checked this answer but the version of the Rails Guide I'm using doesn't include that post_params method, so I haven't required anything.

I'm going through the Rails Guides piece by piece, and I'm confused as to why strong params doesn't seem to be enabled for me. My Rails version is 4.1.7, I believe I've done literally every step of the Rails Guide up to this point, and yet when I submit info through a form without having strong params set up, I'm not raising a Forbidden Attributes error and my database is having entries sent into it. Shouldn't the strong params requirement prevent any kind of entry into my database?

I'm not sure if I've done something incorrectly or if it's operating as it should be and I misunderstood the point. The Rails Guides says I should be seeing an error message in my browser about Forbidden Attributes, but all I'm seeing is "The action 'show' could not be found for ArticlesController."

I have a form in new.html.erb:

<%= form_for :articles, url: articles_path do |f| %>
<p>
    <%= f.label :title %><br>
    <%= f.text_field :title %>
</p>
<p>
    <%= f.label :text %><br>
    <%= f.text_area :text %>
</p>
<p>
    <%= f.submit %>
</p>

And a create method in articles_controller.rb:

class ArticlesController < ApplicationController

    def new
    end

    def create
        @article = Article.new(params[:article])

        @article.save!
        redirect_to @article
    end
end

Any explanation/insight would be appreciated.

Upvotes: 0

Views: 61

Answers (1)

trosborn
trosborn

Reputation: 1668

Sounds like you need a show action in your articles controller:

#articles_controller
def show
  @article = Article.find(params[:id])
end

Upvotes: 1

Related Questions