ruby - Rails: Ajax-enabled form without a model object -
i'm new rails , having hard time figuring out how create form submits on ajax without having corresponding model object.
my use case simple form collects email address , sends email; there's nothing persisted, no model.
in cases do have model, i've had success form_for(@model, remote: true)
. can't seem find right helper case there no model. tried form_tag(named_path, remote: true)
, works, not use ajax.
pointers example example proper controller, .html.erb
, routes.rb
appreciated.
here's how solved it. key using form_tag
, specifying hash argument matched route. business logic, need pass in "id" param, used in controller logic.
<%= form_tag(sendmail_path({ id: 1}), remote: true) %> <%= text_field_tag :email, params[:email] %> <%= submit_tag "send", remote:true %> <% end %>
routes.rb
:
myapp::application.routes.draw post '/sendmail/:id(.:format)' => 'mycontroller#sendmail', :as => 'sendmail' # etc... end
i had supply sendemail.js.erb template updates form after submission.
Comments
Post a Comment