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
Simple_form to handle strong_parameters
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
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.
Carlos Antonio da Silva  
View profile  
 More options Oct 28 2012, 11:28 am
From: Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>
Date: Sun, 28 Oct 2012 13:27:55 -0200
Local: Sun, Oct 28 2012 11:27 am
Subject: Re: Simple_form to handle strong_parameters

I personally don't think this is SimpleForm's responsibility. It's up to
the developer to show the correct fields that are going to be submitted to
a particular controller that handles params with strong_parameters.

In any case, I'm pretty sure it's possible to wrap SimpleForm's behavior in
a new form builder that handles that for you. I can think of something that
receives the "permitted_params" in the form_for call, and automatically
skip attributes that are inside there. Keep in mind that it may be a bigger
problem when you're talking about nested attributes and so on, but I think
it's possible.

On Thu, Oct 25, 2012 at 9:09 AM, Denis Peplin <denis.pep...@gmail.com>wrote:

--
At.
Carlos Antonio

 
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.
Denis Peplin  
View profile  
 More options Nov 1 2012, 2:46 am
From: Denis Peplin <denis.pep...@gmail.com>
Date: Thu, 1 Nov 2012 09:45:47 +0300
Local: Thurs, Nov 1 2012 2:45 am
Subject: Re: Simple_form to handle strong_parameters

I also thought about some wrapper, but for me it is too complex solution.
simple_form is wrapper by itself, and it does not looks very simple. I
agree, that mixing strong_parameters functionality with simple_form code is
not perfect idea. But what about more general functionality, maybe some
filter, that can be used in different ways, without mixing filtering logic
into view code?

It turns out, that it is easier to implement that filter by monkey patching
simple_form's FormBuilder:

https://gist.github.com/3992175

And in a view, I only have to change one line of code, instead of adding
conditions to each line:

<%= simple_form_for(@topic, :defaults => { :display_only =>
permitted_params.topic_attributes } ) do |f| %>

This gist can be released as gem, but only if there is no chances to
include filtering functionality into simple_form gem.

2012/10/28 Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>


 
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.
Carlos Antonio da Silva  
View profile  
 More options Nov 1 2012, 7:23 am
From: Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>
Date: Thu, 1 Nov 2012 09:22:53 -0200
Local: Thurs, Nov 1 2012 7:22 am
Subject: Re: Simple_form to handle strong_parameters

I added a comment to your
gist<https://gist.github.com/3992175#gistcomment-592000> with
a StrongParametersFormBuilder example, that would extend SimpleForm
functionality with your "display_only" option, allowing you to achieve
exactly your example here.

I don't think this is going to be part of SimpleForm any time soon, in my
mind, if the developer doesn't need an attribute, he shouldn't call f.input
with it. If he wants to generalize form at that point, to reuse the same
form with different pages and different "parameters" configuration, then
it's up to him to handle it with a builder extension like that, or ifs. In
the majority of the use cases I've seen, it has been better to just split
the form templates.

Thanks!

--
At.
Carlos Antonio

 
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.
Denis Peplin  
View profile  
 More options Nov 2 2012, 1:41 am
From: Denis Peplin <denis.pep...@gmail.com>
Date: Fri, 2 Nov 2012 08:40:40 +0300
Local: Fri, Nov 2 2012 1:40 am
Subject: Re: Simple_form to handle strong_parameters

2012/11/1 Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>

> I added a comment to your gist<https://gist.github.com/3992175#gistcomment-592000> with
> a StrongParametersFormBuilder example, that would extend SimpleForm
> functionality with your "display_only" option, allowing you to achieve
> exactly your example here.

Looks great, but can't get it working. options[:display_only] is seems
unavailable inside new form builder. I established new Rails application to
test this, please look:

https://github.com/denispeplin/display_filter_demo

> I don't think this is going to be part of SimpleForm any time soon, in my
> mind, if the developer doesn't need an attribute, he shouldn't call f.input
> with it. If he wants to generalize form at that point, to reuse the same
> form with different pages and different "parameters" configuration, then
> it's up to him to handle it with a builder extension like that, or ifs. In
> the majority of the use cases I've seen, it has been better to just split
> the form templates.

I have some filtering in my views too, but not a lot. I think, it will take
some time to gain experience with stuff like strong_parameters, and to
decide, is display_filter really needed or it will only complicate things.


 
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.
Carlos Antonio da Silva  
View profile  
 More options Nov 2 2012, 8:21 am
From: Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>
Date: Fri, 2 Nov 2012 10:21:30 -0200
Local: Fri, Nov 2 2012 8:21 am
Subject: Re: Simple_form to handle strong_parameters

Yeah, it was something quick and dirty, totally untested :D. Will take a
look at your app.

--
At.
Carlos Antonio

 
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.
Carlos Antonio da Silva  
View profile  
 More options Nov 2 2012, 8:31 am
From: Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>
Date: Fri, 2 Nov 2012 10:31:02 -0200
Local: Fri, Nov 2 2012 8:31 am
Subject: Re: Simple_form to handle strong_parameters

Added new comment to the gist, with a hopefully working version:
https://gist.github.com/3992175#gistcomment-592347

Cheers.

On Fri, Nov 2, 2012 at 10:21 AM, Carlos Antonio da Silva <

--
At.
Carlos Antonio

 
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.
Denis Peplin  
View profile  
 More options Nov 8 2012, 11:38 pm
From: Denis Peplin <denis.pep...@gmail.com>
Date: Fri, 9 Nov 2012 07:38:28 +0300
Local: Thurs, Nov 8 2012 11:38 pm
Subject: Re: Simple_form to handle strong_parameters

Now in works. I changed code a little bit to actually display
'display_only' attributes, not filter it out, added comment to gist and
updated display_filter_demo repository.

Thanks!

2012/11/2 Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>


 
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.
Carlos Antonio da Silva  
View profile  
 More options Nov 9 2012, 5:51 am
From: Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>
Date: Fri, 9 Nov 2012 08:50:45 -0200
Local: Fri, Nov 9 2012 5:50 am
Subject: Re: Simple_form to handle strong_parameters

Awesome.. Perhaps you'd like to add an entry to our wiki with the final
working example, so that others could benefit? Thanks!

--
At.
Carlos Antonio

 
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.
Denis Peplin  
View profile  
 More options Nov 12 2012, 9:33 am
From: Denis Peplin <denis.pep...@gmail.com>
Date: Mon, 12 Nov 2012 17:33:21 +0300
Local: Mon, Nov 12 2012 9:33 am
Subject: Re: Simple_form to handle strong_parameters

Done: https://github.com/plataformatec/simple_form/wiki/Attributes-filter

2012/11/9 Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>


 
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.
Carlos Antonio da Silva  
View profile  
 More options Nov 12 2012, 9:46 am
From: Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>
Date: Mon, 12 Nov 2012 12:45:52 -0200
Local: Mon, Nov 12 2012 9:45 am
Subject: Re: Simple_form to handle strong_parameters

Awesome, thanks!

On Mon, Nov 12, 2012 at 12:33 PM, Denis Peplin <denis.pep...@gmail.com>wrote:

--
At.
Carlos Antonio

 
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.
Denis Peplin  
View profile  
 More options Nov 12 2012, 10:30 am
From: Denis Peplin <denis.pep...@gmail.com>
Date: Mon, 12 Nov 2012 18:30:19 +0300
Local: Mon, Nov 12 2012 10:30 am
Subject: Re: Simple_form to handle strong_parameters

Thank you for code!

Please fix article if something wrong.

2012/11/12 Carlos Antonio da Silva <carlosantoniodasi...@gmail.com>


 
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.
End of messages
« Back to Discussions « Newer topic     Older topic »