Skip to content

In goes a hash, out comes hidden fields. Great for preserving Rails parameters without abusing the session.

Notifications You must be signed in to change notification settings

brianhempel/hash_to_hidden_fields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HashToHiddenFields Build Status

Sometimes in your Rails app you want a user to begin an action, log in, then complete the action. You smash their params into the session, let the user log in, then pull their params out of the session when the login is successful. END SESSION STORE ABUSE! A better way is to have the login form resubmit the params.

Add this to your Gemfile:

gem "hash_to_hidden_fields"

Filter the params you want to save and turn them into hidden fields in your form:

<%= hash_to_hidden_fields(@params_to_save) %>

When the form is submitted, all the old params will come through! Nested arrays and nested hashes are all preserved.

Help make it better!

Find a problem? Open an issue. Or, even better, code it yourself and send a pull request:

# fork it on github, then clone:
git clone [email protected]:your_username/hash_to_hidden_fields.git
bundle install
rspec
# hack away
git push
# then make a pull request

License

Public domain; no restrictions.

About

In goes a hash, out comes hidden fields. Great for preserving Rails parameters without abusing the session.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages