Rails:类型错误:对象不支持此属性或方法

斯维特拉娜

所以我正在尝试制作我的第一个 ruby​​ on rails 应用程序。我对 ruby​​ 和 rails 都没有任何经验。我试图找到答案,但没有成功。

我的错误是: C:/Sites/projects/test/app/views/layouts/application.html.erb 其中第 10 行引发:TypeError: Object does not support this property or method Extracted source (about line #10)

我的 application.html.erb:

 <!DOCTYPE html>
<html>
  <head>
    <title>Test</title>
    <%= csrf_meta_tags %>

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.css">

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>

  <body>
    <div class="container">
  <%= yield %>
</div>
  </body>
</html>

我的宝石文件:

source 'https://rubygems.org'
    git_source(:github) do |repo_name|
      repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
      "https://github.com/#{repo_name}.git"
    end


    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '~> 5.1.4'
    # Use sqlite3 as the database for Active Record
    gem 'sqlite3'
    # Use Puma as the app server
    gem 'puma', '~> 3.7'
    # Use SCSS for stylesheets
    gem 'sass-rails', '~> 5.0'
    # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 1.3.0'
    # See https://github.com/rails/execjs#readme for more supported runtimes
    # gem 'therubyracer', platforms: :ruby

    # Use CoffeeScript for .coffee assets and views
    gem 'coffee-rails', '~> 4.2'
    # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
    gem 'turbolinks', '~> 5'
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem 'jbuilder', '~> 2.5'
    # Use Redis adapter to run Action Cable in production
    # gem 'redis', '~> 3.0'
    # Use ActiveModel has_secure_password
    # gem 'bcrypt', '~> 3.1.7'

    # Use Capistrano for deployment
    # gem 'capistrano-rails', group: :development

    group :development, :test do
      # Call 'byebug' anywhere in the code to stop execution and get a debugger console
      gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
      # Adds support for Capybara system testing and selenium driver
      gem 'capybara', '~> 2.13'
      gem 'selenium-webdriver'
    end

    group :development do
      # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
      gem 'web-console', '>= 3.3.0'
    end

    # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

路线文件:

Rails.application.routes.draw do
    root to: redirect('/ideas')
  resources :ideas
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

和控制器:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
end

class IdeasController < ApplicationController
  before_action :set_idea, only: [:show, :edit, :update, :destroy]

  # GET /ideas
  # GET /ideas.json
  def index
    @ideas = Idea.all
  end

  # GET /ideas/1
  # GET /ideas/1.json
  def show
  end

  # GET /ideas/new
  def new
    @idea = Idea.new
  end

  # GET /ideas/1/edit
  def edit
  end

  # POST /ideas
  # POST /ideas.json
  def create
    @idea = Idea.new(idea_params)

    respond_to do |format|
      if @idea.save
        format.html { redirect_to @idea, notice: 'Idea was successfully created.' }
        format.json { render :show, status: :created, location: @idea }
      else
        format.html { render :new }
        format.json { render json: @idea.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /ideas/1
  # PATCH/PUT /ideas/1.json
  def update
    respond_to do |format|
      if @idea.update(idea_params)
        format.html { redirect_to @idea, notice: 'Idea was successfully updated.' }
        format.json { render :show, status: :ok, location: @idea }
      else
        format.html { render :edit }
        format.json { render json: @idea.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /ideas/1
  # DELETE /ideas/1.json
  def destroy
    @idea.destroy
    respond_to do |format|
      format.html { redirect_to ideas_url, notice: 'Idea was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_idea
      @idea = Idea.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def idea_params
      params.require(:idea).permit(:name, :description, :picture)
    end
end

我已经尝试用 application.html.erb 中的默认值替换应用程序。

机架

我标记了一个类似的问题可能会有所帮助 - 他们的解决方案如下:

我从 application.js 中删除了 require_tree 并且它起作用了

//= 需要 jquery
//= 需要 jquery_ujs
//= 需要 turbolinks
// require_tree .

这表明您的 javascript 中某处存在问题 - 如果这种方法有效,我会在那里查找任何问题,和/或将它们一个一个地添加。

我会尝试的另一件事是删除您中的 Turbolinks 选项,javascript_include_tag看看这是否有任何问题。

让我知道这是否有帮助!


编辑:

要直接链接答案中的另一个线程,它在这里:

类型错误:对象不支持此属性或方法

有几个分支:

Pages#home 中的 Rails ExecJS::ProgramError?

Windows 上的 ExecJS::RuntimeError 试图遵循 ruby​​tutorial

那里有一些阅读:)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

VBA对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法Rails Windows 64bit

来自分类Dev

为什么出现此错误:对象不支持Internet Explorer的属性或方法“ forEach”?

来自分类Dev

Javascript错误:对象在IE浏览器中不支持此属性或方法

来自分类Dev

对象不支持此属性或方法

来自分类Dev

IE为什么会出现此错误:对象不支持属性或方法isNaN

来自分类Dev

IE8 JS错误:对象不支持此属性或方法

来自分类Dev

Excel VBA错误438:对象不支持此属性或方法

来自分类Dev

Rails:在Rails 4.1.1中不能包含scss。-TypeError:对象不支持此属性或方法

来自分类Dev

遇到运行时错误'438'对象在Excel宏中不支持此属性或方法

来自分类Dev

“运行时错误'438':对象不支持此属性或方法。” 范围值=范围值

来自分类Dev

错误438对象不支持此属性或方法-带字典的类对象

来自分类Dev

对象不支持此属性或方法ActiveWorkbook对象VBA

来自分类Dev

调试-IE对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法

来自分类Dev

仅在IE8中的jQuery错误“对象不支持此属性或方法”

来自分类Dev

为什么出现此错误:对象不支持Internet Explorer的属性或方法“ forEach”?

来自分类Dev

IE8 Javascript错误:对象不支持此属性或方法

来自分类Dev

Excel VBA,错误“ 438”“对象不支持此属性或方法”

来自分类Dev

IE为什么会出现此错误:对象不支持属性或方法isNaN

来自分类Dev

IE8 JS错误:对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法

来自分类Dev

IE8 JavaScript错误-对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法:oFldr.GetFolder

来自分类Dev

Excel VBA错误438:对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法Chartspace

来自分类Dev

对象在VBA中不支持此属性或方法

来自分类Dev

用户定义类 - 对象不支持此属性或方法

来自分类Dev

对象不支持此属性或方法

Related 相关文章

  1. 1

    VBA对象不支持此属性或方法

  2. 2

    对象不支持此属性或方法Rails Windows 64bit

  3. 3

    为什么出现此错误:对象不支持Internet Explorer的属性或方法“ forEach”?

  4. 4

    Javascript错误:对象在IE浏览器中不支持此属性或方法

  5. 5

    对象不支持此属性或方法

  6. 6

    IE为什么会出现此错误:对象不支持属性或方法isNaN

  7. 7

    IE8 JS错误:对象不支持此属性或方法

  8. 8

    Excel VBA错误438:对象不支持此属性或方法

  9. 9

    Rails:在Rails 4.1.1中不能包含scss。-TypeError:对象不支持此属性或方法

  10. 10

    遇到运行时错误'438'对象在Excel宏中不支持此属性或方法

  11. 11

    “运行时错误'438':对象不支持此属性或方法。” 范围值=范围值

  12. 12

    错误438对象不支持此属性或方法-带字典的类对象

  13. 13

    对象不支持此属性或方法ActiveWorkbook对象VBA

  14. 14

    调试-IE对象不支持此属性或方法

  15. 15

    对象不支持此属性或方法

  16. 16

    仅在IE8中的jQuery错误“对象不支持此属性或方法”

  17. 17

    为什么出现此错误:对象不支持Internet Explorer的属性或方法“ forEach”?

  18. 18

    IE8 Javascript错误:对象不支持此属性或方法

  19. 19

    Excel VBA,错误“ 438”“对象不支持此属性或方法”

  20. 20

    IE为什么会出现此错误:对象不支持属性或方法isNaN

  21. 21

    IE8 JS错误:对象不支持此属性或方法

  22. 22

    对象不支持此属性或方法

  23. 23

    IE8 JavaScript错误-对象不支持此属性或方法

  24. 24

    对象不支持此属性或方法:oFldr.GetFolder

  25. 25

    Excel VBA错误438:对象不支持此属性或方法

  26. 26

    对象不支持此属性或方法Chartspace

  27. 27

    对象在VBA中不支持此属性或方法

  28. 28

    用户定义类 - 对象不支持此属性或方法

  29. 29

    对象不支持此属性或方法

热门标签

归档