No commit activity in last 3 years
No release in over 3 years
Detecting inputs from simple form, saving them in a session in order to do automatic strong parameters in the controller.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 4.0.0
>= 3.0.0
 Project Readme

Code Climate Test Coverage Build Status

SimpleFormStrongParameters

By inspecting which input's you call on simple_form_for, a session variable is generated in order to automatically do strong parameters for the next posted content, making it even more simple and easy to write controllers, because you can leave out the maintenence of *_params-methods completely!

Simply call simple_form_strong_parameters_for instead of simple_form_for and simple_form_strong_parameters(:model_name) instead of model_params.

This project uses MIT-LICENSE.

Install

Add to Gemfile:

gem 'simple_form_strong_parameters'

Usage

In your form use simple_form_strong_parameters_for instead of simple_form_for (but use it as normally):

<%= simple_form_strong_parameters_for @user do |f| %>
 <%= f.input :name %>
<% end %>

In your controller do like this:

class UsersController < ApplicationController
  def new
    @user = User.new
  end

  def create
    @user = User.create!(simple_form_strong_parameters(:user))
    redirect_to user_path(@user)
  end
end

If a field that hasn't been defined as an input is present in the params, then a ActiveModel::ForbiddenAttributesError error will be raised as normally.

You no longer have to maintain a user_params-method every time you change your form!