QUESTION: Are there any security risks or other issues with this implementation? The reason I'm doing this is because I don't want to type f.text_field :field_name
for each form input. This seemed like the most DRY approach. Main concern: is that constants aren't enforced and wondering if this implementation poises a security risk?
class UserController < ApplicationController
def index
end
def new
@user = User.new
@fields = USER_FIELDS
end
def create
render text: params.inspect
end
private
USER_FIELDS = ["first_name", "last_name", "email", "password"]
def require_parmas
params.require(:user).permit(USER_FIELDS)
end
end
User#new view
<%= form_for @user, url: {action: :create} do |f| %>
<% @fields.map do |field| %>
<li>
<%= f.label field %>
<% if field =~ /password/ %>
<%= f.password_field field %>
</li>
<% else %>
<%= f.text_field field %>
</li>
<% end %>
<% end %>
<%= f.submit "Create Your Account" %>
<% end %>