不知道爲什麼我得到這個。我做了一堆閱讀,但我無法做出正面或反面的評論。406在這樣的基本控制器上不可接受
我的控制器:
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無視我的額外PARAMS。
我也應該注意到我的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"
查看http://stackoverflow.com/questions/1414446/weird-406-not-acceptable-error – jschorr
我有。它沒有幫助。 – Trip
自創建以來,我一直通過這個控制器發送params [:mail_type]幾個月,沒有任何問題。現在它不起作用。不知道會有什麼替代方案。 – Trip