Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
I found it annoying that the form_for
method of building forms only worked with models. DuckForm creates a way to
build arbitrary models so you can consistently use the form_for
method to build forms throughout your Rails application.
Good examples of this are search forms, or login forms.
This can also be useful to hide nastly implementation details for form input that touches multiple models.
For example, you have an Account and User and UserRole models.
When a user registers, you want to create a new Account and add a role of 'admin' to the Account for that User.
You can ask for all of the User and Account details in one form, and implement a #save
method on the Registration DuckForm that handles all of these details.
Much better than cluttering up your User model with registration specific callback methods.
Add this line to your Rails application's Gemfile:
gem 'duck_form'
And then execute:
$ bundle
Simply extend the DuckForm class, and add attributes. ActiveModel::Validations
is included for free!
class Registration < DuckForm
attr_accessor :email, :password, :password_confirmation, :account_name
validates :email, :password, :account_name, presence: true
validates :password, confirmation: true
end
You can build your own DuckForms on the fly, for simple cases using DuckForm.build(name, \*attributes, &block)
Use a Has to define attributes with default values.
Also, if you pass a block, it will be class_eval
ed so you can define additional methods for your DuckForm.
# in a controller
class SearchesController < ApplicationController
def search_form
DuckForm.build "Search", :query, max_results: 10 do
def search
Product.search(query, limit: max_results)
end
end
end
helper_method :search_form
def create
search_form.update_attributes(params[:search])
results = search_form.search
respond_with results
end
end
# in a view (haml)
= form_for search_form do |f| # will POST to /searches, override the URL if you'd like
= f.label :query
= f.text_field :query
= f.label :max_results
= f.number_field :max_results
= f.submit
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that duck_form demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.