Rails,default.js是空的,jquery和jquery_ujs没有加载 [英] Rails, default.js is empty, and jquery and jquery_ujs not loaded

查看:109
本文介绍了Rails,default.js是空的,jquery和jquery_ujs没有加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用帮助我获得了答案摆脱这个问题。其实coffee-script-source,v 1.9.x在windows上给出了问题,所以如果你使用v 1.8.0,这个问题就会消失。



包含在你的Gemfile gem'coffee-script-source','1.8.0'



比运行 bundle更新coffee-script-source


I am practicing ruby on rails by using rails guides. In the section 5.13 Deleting Articles they are showing how to create the delete (destroy) functionality. I followed the steps correctly, but the delete confirmation dialogue isn't shown and the articles are not getting deleted. When I checked the chrome developer tools, "jquery" and "jquery_ujs" is not included and the "default.js" is empty. I am running ruby on rails on windows 7.

This is my articles controller,

class ArticlesController < ApplicationController

  def index
    @articles = Article.all
  end

  def show
    @article = Article.find(params[:id])
  end

  def new
    @article = Article.new
  end

  def edit
    @article = Article.find(params[:id])
  end

  def create
    @article = Article.new(article_params)

    if @article.save
      redirect_to @article
    else
      render 'new'
    end
  end

  def update
    @article = Article.find(params[:id])

    if @article.update(article_params)
      redirect_to @article
    else
      render 'edit'
    end
  end

  def destroy
    @article = Article.find(params[:id])
    @article.destroy

    redirect_to articles_path
  end

  private
  def article_params
    params.require(:article).permit(:title, :text)
  end
end

And this is view (app/views/articles/index.html.erb)

<h1>Listing Articles</h1>
<%= link_to 'New article', new_article_path %>
<table>
  <tr>
    <th>Title</th>
    <th>Text</th>
    <th colspan="3"></th>
  </tr>

  <% @articles.each do |article| %>
    <tr>
      <td><%= article.title %></td>
      <td><%= article.text %></td>
      <td><%= link_to 'Show', article_path(article) %></td>
      <td><%= link_to 'Edit', edit_article_path(article) %></td>
      <td><%= link_to 'Destroy', article_path(article),
              method: :delete,
              data: { confirm: 'Are you sure?' } %></td>
    </tr>
  <% end %>
</table>

And this part of the tutorial is used creating this delete/destroy functionality.

Edit: I didn't edit any js file, because the said tutorial didn't say to alter any js file at this point, but as someone asked in the comment so I'm adding the js file, this is how the application.js looks.

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

Edit 2: (edited after @NitishParkar's comments)
As I was following the Rails Guide, when I reached to this point, where the CRUD portion is completed for the articles controller. This is how the listed articles and the links to "show", "edit" and "destory" looked.

When I inspected the source for the first destroy(delete) link, it looked like this: <a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/articles/1">Destroy</a>

But when I clicked it, it didn't show any confirmation dialog box and the browser jumped to http://localhost:3000/articles/1 and the article wasn't deleted.

解决方案

Everything is OK from your side. You said that you're on Windows 7, I also experienced this problem once when I needed to run rails on windows for some reason. Than I found an answer here which helped me to get out of this problem. Actually coffee-script-source, v 1.9.x gives problem on windows, so if you use v 1.8.0 instead, this problem will go away.

include in your Gemfile gem 'coffee-script-source', '1.8.0'

than run bundle update coffee-script-source

这篇关于Rails,default.js是空的,jquery和jquery_ujs没有加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆