Reputation: 517
I'm working on a little test and want to see if my thinking is correct.
I have a form that is going to take in a string of data. When its submitted, it going to do some formatting and then display the formatted data.
I originally thought to have the form in the index action, post the data to create then redirect back to index with the formatted data. I don't like this because the formatted data is appended url with a query string (too ugly)
Is it reasonable have the form post to the index action and format the data in a helper method and display it. My index method would look something like this:
def index
if params
# Do Stuff
end
end
Upvotes: 0
Views: 33
Reputation: 3465
Perhaps you might achieve what you're looking for by using a table-less model (no DB connection required) and the built in ActiveRecord
niceties to display this for you.
class Person
include ActiveModel::Model
attr_accessor :name, :email
...
end
Then display in your index action, and use the form to send a POST
to create, and then simply display a template which shows the formatted data.
# controller
def index
@person = Person.new
end
def create
@person = Person.new(person_params)
render :formatted # formatted.html.erb
end
# index.html.erb
<%= form_for @person %>
...
<% end %>
Upvotes: 1