不确定我为什么会这样做。我做了一堆阅读,我无法做出正面或反面。
我的控制器:
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
那里什么都没有。它是一个多部分(图像)表单提交..可能与某些事情有关吗?
更新
一些irb的东西:
>> admin_emails_path(:mail_type => @emails.mail_type)
"/admin/emails?mail_type=magic_email"
>> admin_emails_path(@emails)
"/admin/emails.%23%3Cemail:0x109eb6360%3E"
第二个例子似乎是它实际返回的内容,忽略了我在URL中的其他参数。
我还应该注意,我的edit
重定向是相同的,它运作正常。
更新2
为了表明这种情况是多么无助,我已将控制器改为:
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
我仍然明白这一点:
Completed in 7401ms (View: 3, DB: 7) | 406 Not Acceptable [http://localhost/admin/emails.%23%3Cemail:0x109fd2a28%3E]
路线
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_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"
答案 0 :(得分:3)
请求的MIME类型由传入的文件扩展名确定。
此处的错误如下:
>> admin_emails_path(@emails)
"/admin/emails.%23%3Cemail:0x109eb6360%3E"
不应将助手admin_emails_path传递给电子邮件列表。这个收集路径应该自己工作。当您传入@emails对象时,它正在尝试将其编码到URL中并注入一个句点,其中的rails正在解析为文件扩展名(%23%3Cemail的url解码版本:0x109eb6360%3E)。
更改参考:
admin_emails_path(@emails)
为:
admin_emails_path
...你不会看到这些格式错误。