0
votes

I'm new to rails and mongodb, and have a simple form attempting to create a category tree.

Whenever I refresh the page, a new entry is put into the database. I'm not clicking the 'submit' button, just page refresh.

The form looks like this

<%= form_for Activity.create do |f| -%>
  <%= f.text_field :activity_name % >
<%= f.submt "add action" %<
<% end %>

my model is

class Activity
       include MongoMapper::Document

    key    :activity_name, :type => String
    key    :parent,        :type => ObjectId
    key    :acnestors,   Array

    timestamps!
end

my routes has a single entry for activity

map.activity '/activity/:activity_id', :controller => 'activities', :action => 'show'

though I call create from the form, my create function in my controller is empty. The form is included in the show page via render, but that shouldn't matter.

Any idea why a page refresh would act as a form submit?

1
there is a typo: <%= f.submt "add action" %< should be: <%= f.submit "add action" %>Martin Labuschin

1 Answers

0
votes

You are calling Activity.create in your form helper. This is going to create (in the Rails sense, which will also save it to the db) a new object every time you load the page.