Creating and submitting an active Ajax post form in Rails best practices?

Well, all of you wonderful people are there; In my UI, I am creating a form where users can add new posts via Ajax.

Users will be able to add multiple entries from the form (it will be cleared after each post) and I'm wondering what would usually be the best way to customize the form.

If I want to use form_for helpers I need to have a model instance to work with ie

def index
  @record = Record.new
end

      

However, I'm not sure if this is better from an ajax perspective.

Should I not create an object and just use form_tag and write a method to create a post from my custom form. i.e.

  <%= form_tag "/create_record" do %>
     <%= text_field_tag :record_name %>
     <%= text_area_tag :record_description %>
     <%= submit_tag %>
   <% end -%>

      

Then grab the attributes in the controller and manually create the entry.

The second way will work, but I don't know if it's better. Can anyone shed some light on how the build process works? Do you need to create a new object for every post you want to submit?

Thanks!

+2


a source to share


1 answer


you can use

form_remote_tag

      



instead of form_tag http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001648

+1


a source







All Articles