English 中文(简体)
铁路 3 406 在试图使用格式方面,不可接受的错误。 js, Can t change content-type or [duplicate]
原标题:Rails 3 406 Not Acceptable error on attempting to use format.js, Can t change content-type either [duplicate]
This question already has answers here:
Closed 10 years ago.

Possible Duplicate:
Weird “406 not acceptable” error

我已坐在这个无休止的讲台上! 在我的铁路3中,我有一个“新”的研究网页和一个“编辑”网页。 每一页都有相同的部分,在一份研究报告中增加多种出版物。 在我的编辑网页上,通过js对网页进行更新的工作是罚款的,但在研究/更新中,当我创建新的出版物时,我发现406个不可接受的错误。 我的出版物/军事行动就是这样:

def create
  @publication = Publication.new(params[:publication])
  @publication.display_number = @publication.get_display_number(session[:study_id])
  @publication.save
  @secondary_publications = Publication.find(:all, :order =>  display_number ASC , :conditions => {:is_primary => false, :study_id => session[:study_id]})  

 respond_to do |format|
  if @publication.save
        format.js {
            render :update do |page|
                page.replace_html  secondary_publication_table , :partial=> publications/table  
            end
        }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @publication.errors, :status => :unprocessable_entity }
  end
  end
  end

我尝试了各种方式,我可以找到确定内容类型的方法(我无需在其他网页上这样做)

render :update, :content-type => "text/javascript" do |page|

但是,在我称之为行动时,我无法从案文/html上改变内容类型。 帮助?

提前感谢!

Edit: the code submitted in the form looks like this:

<%= nested_form_for @publication, :remote => true, :html=>{:id=> secondary_pub_form } do |f| %>
<%= f.text_field :title %>
<%= f.text_field :author, :size => 12 %>
<%= f.text_field :country, :size => 10 %>
<%= f.text_field :year, :size => 6 %>

......

 <% end %>

The “nested_form_for” is a plugin that I m used. This setup has work on other pages in same way (using this plugin,loading a part, etc)

最佳回答

我不清楚这里的意图是什么。 你们是否总是拒绝? 愿您:

respond_to do |format|
  format.html { render :action => "new" }
  format.xml  { render :xml => @publication.errors, :status => :unprocessable_entity }
  format.js do
    if @publication.save
      render :update do |page|
        page.replace_html  secondary_publication_table , :partial=> publications/table  
      end
    else
      # handle failing AJAX request somehow
    end
  end
end
问题回答

查阅您的申请。

//= require jquery_ujs

恳请在你的控制人员中添加以下内容;与之前的“过滤器”相差甚远(确切地说,这是最终的结果)。

respond_to :html, :js

When using jQuery be sure that you have included jquery_ujs.js in your layout otherwise you could also recieve 406 http errors





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签