I get the following error
No route matches [POST] "/events"
with this setup:
config/routes.rb
namespace :admin do
#...
resources :events
#...
end
(…)admin/events_controller.rb
class Admin::EventsController < Admin::AdminController
def index
@events = Event.all
end
def new
@event = Event.new
end
def create
@event = Event.new(params[:event])
if @event.save
redirect_to [:admin, admin_events_url]
else
render :action => "new"
end
end
def edit
@event = Event.find(params[:id])
end
end
(…)admin/events/_form.html.erb
<%= form_for([:admin, @event]) do |f| %>
I can’t figure out what I am doing wrong!
Update
I get this error when I try to POST the from data while creating a new event entry
Update 2
The opening form tag inside events/new:
<form accept-charset="UTF-8" action="/admin/events" enctype="multipart/form-data" id="new_event" method="post">
the result of rake routes:
admin_events GET /admin/events(.:format) admin/events#index
POST /admin/events(.:format) admin/events#create
Navigating to /admin/events/ using GET works just fine.
Update 3
It works fine on Windows 8 x64 bit with Ruby 1.9.3, Rails 3.2 and Mongrel. It doesn’t work with Ruby 1.8.7, Rails 3.2 and Phusion Passenger on a linux server (the host).
Update 4
Oh. It appears Rails isn’t very happy if you send it a form with multipart/form-data encoding! Removing the file-upload fixed this issue.
For what it’s worth the only thing that looks fishy to me about your controller is your redirect. You should be able to just do: