10

How to automatically submit a Rails form when visiting a page

 3 years ago
source link: https://www.codesd.com/item/how-to-automatically-submit-a-rails-form-when-visiting-a-page.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to automatically submit a Rails form when visiting a page

advertisements

i have a form which i want to be auto submited when a page is visited maybe through jquery or any other means the reason why is that i want a create action to be triggered so i can make use it my table for the form is

class CreateWhatsups < ActiveRecord::Migration
  def change
    create_table :whatsups do |t|
      t.string :details, :default => "visited"
      t.integer :user_id

      t.timestamps
    end
  end
end

my form includes

<%= form_for(@whatsup) do |f| %>
  <div class="field">
    <%= f.label :details %><br>
    <%= f.text_field :details %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

how do i make this form auto submit when i place it anywhere in my rails application without clicking the submit button


Use the document.ready event of JQuery For example

$(document).ready(function(){
$("formname").submit();
});


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK