POST Requests are mapped to my index action

Hi all !
I’ve got a problem in my application. I’ve written a bug_reports
controller. It is pretty RESTful, there are index, new and create
actions. Everytime I submit a new bug_report, the index action is
called, not the create action, you can see the log here:
http://pastie.org/258857.
My form looks like this:

<% form_for @bug_report, :url => bug_reports_path do |f| -%>
<%= f.text_field :title, :value => "Title" %>
<%= f.text_area :body %>
<%= f.submit "Submit", :disable_with => 'Submiting...' %>
<% end -%>

My routes.rb contains this line: map.resources :bug_reports

And finally, my BugReportsController looks like this:
class BugReportsController < ApplicationController
login_required
def index
@bug_reports = BugReport.all
end

def new
@bug_report = BugReport.new
end

def create
@bug_report = BugReport.new params[:bug_report]
if @bug_report.save
flash[:notice] = “Thank you for submitting this bug.”
else
flash[:warning] = “Your bug report was not saved. Please try
again.”
end
redirect_to root_url
end
end

This error doesn’t occur in other parts of my app. I really don’t know
why this happens, I hope you can help me. Thank you very much in
advance,
Christoph

PS: I’ve written a small patch regarding
options_from_collection_for_select. You can find it here:
http://rails.lighthouseapp.com/projects/8994/tickets/890-in-options_from_collection_for_select-text-value_method-are-chainable.
I would be happy if someone would give me feedback on this.

On Sun, Aug 24, 2008 at 1:27 AM, Christoph [email protected]
wrote:

Try using the following:

<% form_for(@bug_report) do |f| -%>

Good luck,

-Conrad

No, this doesn’t help. The form seems to be correct regardless if I
specify the url or not:

Hi, I was able to get it working here without any issues. I built the
application from scratch. Here’s the new.html.erb:

New bug_report

<% form_for(@bug_report) do |f| %>
<%= f.error_messages %>

<%= f.label :title %>
<%= f.text_field :title %>

<%= f.label :body %>
<%= f.text_area :body %>

<%= f.submit "Create" %>

<% end %>

<%= link_to ‘Back’, bug_reports_path %>

-Conrad

Hi, try the following:

POST /bug_reports

POST /bug_reports.xml

def create
@bug_report = BugReport.new(params[:bug_report])

respond_to do |format|
  if @bug_report.save
    flash[:notice] = 'BugReport was successfully created.'
    format.html { redirect_to(@bug_report) }
  else
    format.html { render :action => "new" }
  end
end

end

Don’t you think the error is somewhere in the code handling the
request. The form is generated correct, and it also sends the request
correct to the server, with all parameters, as you can see in the log
here: http://pastie.org/258857

Sometimes my router freaks out until I restart the server. It will
default to :controller/:action, which has the effect of displaying
“index”, even though I POST-ed (which should route it to “create”).

When stuff goes nutty, I always restart the server.

On Sun, Aug 24, 2008 at 4:18 AM, Christoph [email protected]
wrote:

Don’t you think the error is somewhere in the code handling the
request. The form is generated correct, and it also sends the request
correct to the server, with all parameters, as you can see in the log
here: http://pastie.org/258857

I don’t think that the request is correct because it should look like
the
following:

Processing BugReportsController#create (for 127.0.0.1 at 2008-08-24
04:29:26) [POST]
Session ID:
BAh7BzoMY3NyZl9pZCIlZDNlNzUzMTBiYTg4OGM5NjI2MWNlNmJmNDdmOWIz
MjciCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh
c2h7AAY6CkB1c2VkewA=–38e907fd59880233fd4f597c3f76448f80efa3b1
Parameters: {“bug_report”=>{“title”=>“This is a test.”, “body”=>“This
is a
test.”}, “commit”=>“Create”,
“authenticity_token”=>“69184209cf20041cc992c5f33367e7e328932e42”,
“action”=>“create”, “controller”=>“bug_reports”}
BugReport Create (0.000863) INSERT INTO “bug_reports” (“created_at”,
“title”, “body”, “updated_at”) VALUES(‘2008-08-24 11:29:26’, ‘This is a
test.’, ‘This is a test.’, ‘2008-08-24 11:29:26’)
Redirected to http://localhost:3000/bug_reports/0
Completed in 0.01773 (56 reqs/sec) | DB: 0.00086 (4%) | 302 Found [
http://localhost/bug_reports]

Your code is performing a GET instead of a POST. Thus, you’re hitting
the
index action instead of the create action.

Thank you, I don’t know why but routing is correct now. Restarting the
server seemed to work.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs