Reputation: 27114
Not sure why I'm getting this. I did a bunch of reading and I can't make heads or tails of this.
My controller:
def create
@emails = Email.new(params[:email])
respond_to do |format|
if @emails.save
flash[:notice] = 'Email was successfully created.'
format.html { redirect_to admin_emails_path(:mail_type => @emails.mail_type) }
format.xml { render :xml => @emails, :status => :created, :location => @emails }
else
format.html { render :action => "new" }
format.xml { render :xml => @emails.errors, :status => :unprocessable_entity }
end
end
end
Nothing crazy there. Its a multipart(images) form submission..maybe that has something to do with?
Update
Some irb stuff:
>> admin_emails_path(:mail_type => @emails.mail_type)
"/admin/emails?mail_type=magic_email"
>> admin_emails_path(@emails)
"/admin/emails.%23%3Cemail:0x109eb6360%3E"
The second example seems to be what it actually is returning, ignoring my additional params in the URL.
I should also note that my edit
redirect is identical, and it works perfectly.
Update 2
Just to show how completely helpless this situation is, I've changed my controller to this :
if @emails.save
flash[:notice] = 'Email was successfully created.'
debugger
format.html { render :action => "new" } # <=== WTF ?
format.xml { render :xml => @emails, :status => :created, :location => @emails }
else
And I still get this:
Completed in 7401ms (View: 3, DB: 7) | 406 Not Acceptable [http://localhost/admin/emails.%23%3Cemail:0x109fd2a28%3E]
Routes
admin.resources :emails, :collection => {:test_email => :get}, :member => {:update_current => :get, :send_email => :get, :duplicate => :get} do |email|
email.resources :distributions, :collection => {:delete_dist => :get}
end
Form
- form_for @emails, :url => admin_email_path(@emails), :id => "email_form", :html => {:multipart => true} do |f|
... lots of stuff ..
.clear
%p
= f.submit 'Save Email', :class => "button"
Upvotes: 4
Views: 982
Reputation: 19145
The MIME type for the request is determined by the file extension incoming.
The error here is the following line:
>> admin_emails_path(@emails)
"/admin/emails.%23%3Cemail:0x109eb6360%3E"
The helper admin_emails_path should not be passed the list of e-mails. This collection path should work on it's own. When you pass in the @emails object, it's trying to encode it into the URL and injecting a period, which rails is parsing like a file extension (the url decoded version of %23%3Cemail:0x109eb6360%3E).
Change the reference from:
admin_emails_path(@emails)
to:
admin_emails_path
...and you will not see these format errors.
Upvotes: 3