为什么我的图像标签在 windows 中的 ruby​​ on rails 中不起作用 [英] Why my image tag wont work in ruby on rails in windows

查看:17
本文介绍了为什么我的图像标签在 windows 中的 ruby​​ on rails 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在对图像进行 CRUD.. 在视图中显示图像时遇到错误ExecJS::ProgramError in Products#index TypeError: Object does not support this property or method"

I am currently doing a CRUD with image.. Am encountering error "ExecJS::ProgramError in Products#index TypeError: Object doesn't support this property or method" when I displaying the image in my view

问题:我应该如何在视图中显示我的图像?这是为什么?

Question: How should I display my image in my view? Why is that?

注意:我的朋友没有安装 imagemagik & 之类的东西.回形针..我还尝试在我的视图(资产/图像文件夹)中显示静态图像,但它不起作用

NOTE: My friend didn't install anything like imagemagik & paperclip.. I also tried to display a static image in my view(assets/images folder) and its not working

查看

<html>
<head>
    <title>MY STORE!</title>
</head>
<body>
    <h1><align="center"> WELCOME TO MY STORE</h1>
    <%= link_to 'Add Product', new_product_path %>
    <table border = "1" width="100%">
        <tr>
            <td>ID</td>
            <td>Name</td>
            <td>Image</td>

            <td>Size</td>
            <td>Price</td>
            <td>Created At</td>
            <td>Updated At</td>
            <td>Action</td>
        </tr>
        <% @product.each do |p| %>

        <tr>
            <td><%= p.id %></td>
            <td><%= p.name %></td>

            <td><%= image_tag p.image %></td>
            <td><%= p.size %></td>
            <td><%= p.price %></td>
            <td><%= p.created_at.strftime("%B, %d, %Y") %></td>
            <td><%= p.updated_at.strftime("%B, %d, %Y") %></td>
            <td>
            <%= link_to 'View', product_path(p) %>
            <%= link_to 'Edit', edit_product_path(p) %>
            </td>
        </tr>
        <% end %>

    </table>
</body>
</html>

架构

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170406144121) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "carts", force: :cascade do |t|
    t.integer  "product_id"
    t.integer  "price"
    t.string   "status"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "products", force: :cascade do |t|
    t.string   "name"
    t.string   "size"
    t.float    "price"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string   "image"
  end

  create_table "user", id: :integer, default: -> { "nextval('customers_id_seq'::regclass)" }, force: :cascade do |t|
    t.string   "full_name"
    t.string   "product_name"
    t.string   "size"
    t.float    "price"
    t.datetime "created_at",   null: false
    t.datetime "updated_at",   null: false
  end

  add_foreign_key "carts", "products"
end

推荐答案

该错误通常与 CoffeeScript 与 Windows 的兼容性问题有关.降级 gem 应该可以解决它.

The error is commonly related to a CoffeeScript compatibility issue with Windows. Downgrading the gem should solve it.

找到您的 coffee-script-gem 并将其更改为以下内容:

Locate your coffee-script-gem and change it for the following:

gem 'coffee-script-source', '1.8.0'

然后运行:

bundle update coffee-script-source

*如果此解决方案不起作用,请检查错误指向的位置(文件和行),并更新您的问题.

*Please check where the error points to (file and line) if this solution doesn't work, and update your question.

这篇关于为什么我的图像标签在 windows 中的 ruby​​ on rails 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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