ben
ben

Reputation: 29777

Strange Rails behaviour when trying to submit a form

I have a notes model, which has a many-to-many relationship with the users model. In the index view in the notes controller I have this form:

<form id='note_form' method="post" action="/notes/temp_path" >
    <input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />        
    <input type="text" size="30" name="start_date" id="start_date">
</form>

which points to the temp_path action in the notes controller. For some reason when this form is submitted, instead of running the code in the temp_path action, Rails is trying to load a certain note, and because it can't, it redirects back to index.

Started POST "/notes/temp_path" for 127.0.0.1 at 2010-12-08 22:08:25 +1000
DEPRECATION WARNING: Setting filter_parameter_logging in ActionController is deprecated and has no longer effect, please set 'config.filter_parameters' in config/application.rb instead. (called from <class:ApplicationController> at /Users/ben/rails_projects/note_prog/app/controllers/application_controller.rb:6)
  Processing by NotesController#temp_path as HTML
  Parameters: {"authenticity_token"=>"Ck6NmmYO86rvJSEsiqpIMkcaiErEhV7s/XMzjka15AI="}
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE ("users"."id" = 56) LIMIT 1
  UserNote Load (0.2ms)  SELECT "user_notes".* FROM "user_notes" WHERE ("user_notes"."note_id" = 0)
Redirected to http://localhost:3000/notes

I'm pretty sure the WHERE ("user_notes"."note_id" = 0) bit is causing the problem. But I'm not sure why this is even being done? Based on the line above it, User Load (0.3ms) SELECT "users".* ... it seems like it's behind the scenes Rails stuff. Nowhere in the temp_path action do I need to load an existing note. How can I stop this? I'm using Rails 3.0.1. Thanks for reading.

Upvotes: 0

Views: 98

Answers (1)

Arsen7
Arsen7

Reputation: 12820

You should show us the code of your controller. Have you any 'redirect_to' statements there? With any conditions?

Maybe you have some filters in your controller, maybe in ApplicationController? From the deprecation warning I see that you may have some code there.

Upvotes: 1

Related Questions