Rails How to build a form that is not specific to one Record in a Model
in my add I have a Permission model with (user_id, role_id, project_id).
What I am trying to do now is build a CSV import where a user enters a long list of CSV email data, and then the app parses to find all valid emails and then creates permissions.
So in my开发者_开发知识库 permissions controller I created:
def csv_import
end
But in my view, I'm not sure how to build the form? How do I build a form with a textarea field? And where should it post to?
Thanks for the advice
A POST of a multi-entry CSV file doesn't fit into the standard REST API. You've already defined your controller action csv_import
so POST to whatever route you've mapped that action.
Since you're not really POSTing field values that map directly to table columns, it sounds like you're going to want to grab the CSV data and parse it manually.
Use the standard ActionView helpers: form_tag
for the form, text_area_tag
for the text area. Name them whatever you want--csv_form
and maybe csv_data
. Then iterate through each line of the CSV data, i.e.
params['csv_data'].each_line do |line|
data = line.split(',')
...
end
精彩评论