
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Dynamically add nested fields to your Rails forms.
When clicked, link_to_add_fields
will render the association's fields partial
above it.
link_to_remove_fields
will hide the HTML element matching it's
target css selector. It also sets a truthy value in the hidden input field
closest to it, name this field _destroy
to remove models.
After seeing this idea in a Rails casts episode I ended up using it so often I thought it worth making a gem.
Make sure you have jQuery installed.
Add this line to your application's Gemfile:
gem 'link_to_add_fields'
Then execute:
$ bundle
And require link_to_add_fields
in application.js, after jQuery.
//
//= require jquery
//= require link_to_add_fields
//= require_tree .
link_to_add_fields(name, builder, association, options = {}) => String
link_to
.posts/comment_fields
link_to
.link_to_remove_fields(name, target, options = {}) => String
link_to
.link_to
.post_form.html.erb
<%= form_for @post do |f| %>
<%= f.label :name %>
<%= f.text_field :name %><br>
<%= f.label :body %>
<%= f.text_area :body %><br>
<%= f.fields_for :comments do |ff| %>
<%= render partial: "comment_fields", locals: { f: ff } %>
<br>
<% end %>
<%= link_to_add_fields 'Add comment', f, :comments %><br>
<%= f.submit %>
<% end %>
comment_fields.html.erb
<div class="comment_fields">
<%= f.label :body, 'Comment' %>
<%= f.text_area :body %><br>
<%= f.hidden_field :_destroy %>
<%= link_to_remove_fields 'Remove comment', '.comment_fields' %>
</div>
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that link_to_add_fields 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
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.