简体   繁体   English

ActionController :: UnknownFormat(Ruby on Rails)

[英]ActionController::UnknownFormat (Ruby on Rails)

I am creating a Ruby on Rails application where I render my 'new.html.erb' (in my klass controller) and on top of it render my partial '_select_previous.html.erb,' also, I have a 'link_to' to switch back and forth from one to the other. 我正在创建一个Ruby on Rails应用程序,在其中渲染我的“ new.html.erb”(在我的klass控制器中),并在其顶部渲染我的部分“ _select_previous.html.erb”,此外,我还有一个“ link_to”从一个到另一个切换。 However, when I try to start my project at the 'index.html.erb' and then use a 'link_to' to go to the new file, it shows me that error above. 但是,当我尝试从“ index.html.erb”启动我的项目,然后使用“ link_to”转到新文件时,它向我显示了上面的错误。

I am using jQuery to do the switching from one view to the other. 我正在使用jQuery从一个视图切换到另一个视图。

Here is my new.html.erb: 这是我的new.html.erb:

<p> Or select from the previous created classes <%= link_to "here", 
new_klass_path, id: "link_to", :remote => true %> </p>

<div id="previous">
   <%= render :partial => 'select_previous' %>
</div>

<div id="content">
 <!-- Ruby form -->
</div>

This is my klasses controller: 这是我的klasses控制器:

def index
    @klass = Klass.all.paginate(:page => params[:page])
    #import_klasses(@klass)
end

def new
    @klass = Klass.new
    #saved = @klass.save
    #@klass.save!
    #if saved
       #s1 = Student.last.id
       #k1 = Klass.last.id
       #@enrollments = Enrollment.new(student_id: s1, klass_id: k1)
       #binding.pry
       #@enrollments.save!
     #redirect_to :controller => 'enrollments', :action => 'index'
     #flash[:alert] = "Class Created"
  #end
#end

  respond_to do |format|
     format.html {}
     format.js
  end
end

And this is my show.js: 这是我的show.js:

$(document).ready(function() {
$("#days").hide();
$("#grade").hide();
$("#class").hide();
$("#all").hide();
$("#previous").hide();

$("#link_to").click(function () {
    var count = $(this).data("count") || 0;
    if(count == 1)
    {
        $("#content").hide();
        $("#previous").show();
    }
    else if(count == 2)
    {
        $("#content").show();
        $("#previous").hide();
        count = 0;
    }

    $(this).data("count", ++count);
});
});

Thank in advance for any help you may provide me. 在此先感谢您为我提供的任何帮助。

My last attempt, as I am out of my depth it seems. 我的最后一次尝试,似乎超出了我的深度。 Use this along with your original code, files unrenamed. 与原始代码一起使用,文件未重命名。 Leave your js file where it is. 将您的js文件保留在原处。

respond_to do |format|
    format.html {}
    format.js do
        redirect('/assets/show.js')
    end
end

Though I really appreciate all the effort that has been put towards solving this question, I must advice that I found the solution to the problem. 尽管我非常感谢为解决这个问题而付出的所有努力,但我必须建议我找到了解决问题的方法。

The error was on my index.html.erb, which I did not put because I thought it had nothing to do with the problem. 错误出在我的index.html.erb上,我没有放它,因为我认为这与问题无关。 My index looked like this: 我的索引如下所示:

<div>
    <%= link_to "Create new class", new_klass_path(@klass) %>
</div>

The unknown format error came because it did not know what "@klass" was; 出现未知格式错误是因为它不知道“ @klass”是什么。 or so I believe. 或者我相信。 As soon as I took it away, the transition from one page to the other went smoothly. 我一拿走,就可以顺利地从一页过渡到另一页。 Moreover, it looks like this know: 而且,看起来像这样知道:

<div>
    <%= link_to "Create new class", new_klass_path %>
</div>

If this pisses anyone off, I deeply apologize. 如果这惹恼了任何人,我深表歉意。 I really appreciate everyone's help. 我真的很感谢大家的帮助。 I am going to try to level up quickly, to give you guys checks for useful answers. 我将尝试快速升级,以便为您检查有用的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ruby on Rails-AJAX问题(ActionController:UnknownFormat) - Ruby on Rails - Issues with AJAX (ActionController:UnknownFormat) Rails 6.0.1 中 Ajax 请求的 ActionController::UnknownFormat 错误 - ActionController::UnknownFormat error with Ajax request in Rails 6.0.1 在Ruby on Rails中的ActionController :: InvalidAuthenticityToken - ActionController::InvalidAuthenticityToken in ruby on rails 带有远程true的AJAX上的ActionController :: UnknownFormat - ActionController::UnknownFormat on AJAX with remote true jQuery文件上传ActionController :: UnknownFormat - jQuery File Upload ActionController::UnknownFormat Rails,输入模糊后自动提交表单返回:ActionController :: UnknownFormat - Rails, auto-submit form after input blur returns: ActionController::UnknownFormat 在Rails中使用link_to渲染部分onclick时,返回错误ActionController :: UnknownFormat - Error ActionController::UnknownFormat returned when rendering partial onclick with link_to in rails ActionController::UnknownFormat in RegistrationsController#create (Devise) - ActionController::UnknownFormat in RegistrationsController#create (Devise) 使用respond_to do | format |时ActionController :: UnknownFormat - ActionController::UnknownFormat when using respond_to do |format| ActionController :: InvalidAuthenticityToken轨道5 - ActionController::InvalidAuthenticityToken rails 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM