Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Simple_form to handle strong_parameters
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Denis Peplin  
View profile  
 More options Oct 25 2012, 7:09 am
From: Denis Peplin <denis.pep...@gmail.com>
Date: Thu, 25 Oct 2012 04:09:01 -0700 (PDT)
Local: Thurs, Oct 25 2012 7:09 am
Subject: Simple_form to handle strong_parameters

Hello!

I have watched Railscast about strong_parameters,
http://railscasts.com/episodes/371-strong-parameters (sorry, for
subscribers only), and implemented that solution.

Author suggested to filter out forbidden attributes. And it is really
needed, because strong_parameters will not raise exception on attempt to
change forbidden attribute. Success message will be displayed to user, but
attribute will stay unchanged. It is expected behaviour
(https://github.com/rails/strong_parameters/issues/54#issuecomment-977...)

So, that Railscast's code to filter out forbidden attribute is:

<% if permitted_params.topic_attributes.include? :sticky %>
<div class="field">
  <%= f.check_box :sticky %>
  <%= f.label :sticky %>
</div>
<% end %>

Using simple_form it can be written like this:

<%= f.input :sticky, :as => :boolean if
permitted_params.topic_attributes.include?(:sticky) %>

It's already too much I think. But it is only one attrbute. For five
attributes it will be five permitted_params.topic_attributes.include?()

It probably can be shortened, but still there is a need to specify some
condition for each attribute to filter out forbidden ones.

So maybe simple_form gem is the right place to auto-apply strong_parameters
permissions? Or there is another way to do it?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.