我想创建一个新文件夹app/assets,在这个文件夹中我有一些文件,每个文件都有css文件夹和javascript文件夹,如下面给出的地址:
app/assets/plugins/bootstrap/css/bootstrap.min.css
app/assets/plugins/bootstrap/js/bootstrap.min.js
我使用下面的代码来定义css文件,但不是true,rails无法找到并加载bootstrap.min.css:
<%= stylesheet_link_tag "bootstrap.min", media: "all", "data-turbolinks-track" => true %>
<%= stylesheet_link_tag "../plugins/bootstrap/css/bootstrap.min", media: "all", "data-turbolinks-track" => true %>
Run Code Online (Sandbox Code Playgroud)
我怎样才能申报css,并javascript从plugin文件夹?
注意:当我想css通过此地址在浏览器中查看文件时:
http://localhost:3000/assets/plugins/bootstrap/css/bootstrap.min.css
Run Code Online (Sandbox Code Playgroud)
我得到以下错误:
No route matches [GET] "/assets/plugins/bootstrap/css/bootstrap.min.css"
但是对于存在的css文件assets/stylesheets/我可以在浏览器中通过输入地址看顶部的css文件.为什么不同的beetwin stylesheets和plugins目录?
我写这个javascript代码:
context.shadowOffsetX = 5;
context.shadowOffsetY = 5;
context.shadowBlur = 4;
context.shadowColor = 'rgba(255, 0, 0, 0.5)';
context.fillStyle = '#f00';
context.fillRect(x, y, w, h);
Run Code Online (Sandbox Code Playgroud)
我在照片上添加了这个脚本,我希望看到图像的颜色,但无法为此脚本添加透明度.
在 Rails 项目中,我有 3 个控制器和模型,用户、职责和配置文件。我有以下代码:
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_one :responsibility
has_one :profile
before_create :build_responsibility
before_create :build_profile
end
Run Code Online (Sandbox Code Playgroud)
responsibility.rb
class Responsibility < ActiveRecord::Base
belongs_to :user
end
Run Code Online (Sandbox Code Playgroud)
profile.rb
class Profile < ActiveRecord::Base
belongs_to :user
validates :user_id, uniqueness: true
validates_numericality_of :nic_code, :allow_blank => true
validates_numericality_of :phone_number
validates_length_of :phone_number, :minimum => 11, :maximum => 11
validates_length_of :nic_code, :minimum => 10, :maximum …Run Code Online (Sandbox Code Playgroud) 我写这个HTML代码:
<div id="container">
<canvas id="imageView" width="1181" height="1181">
<p>Unfortunately, your browser is currently unsupported by our web
application.</p>
</canvas>
<script type="text/javascript">
window.onload = function() {
var c = document.getElementById('imageView');
var cxt = c.getContext('2d');
var img = new Image();
img.src = "map.jpg";
cxt.drawImage(img, 0, 0);
};
</script>
</div>
Run Code Online (Sandbox Code Playgroud)
并写这个javascript:
this.mousemove = function(ev) {
if (!tool.started) {
return;
}
var x = Math.min(ev._x, tool.x0),
y = Math.min(ev._y, tool.y0),
w = Math.abs(ev._x - tool.x0),
h = Math.abs(ev._y - tool.y0);
context.clearRect(0, 0, canvas.width, canvas.height);
if …Run Code Online (Sandbox Code Playgroud) 我使用"paperclip","〜> 4.1"(在Windows 8上)将图片保存到我的产品中.我有下面的代码:
products_controller:
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
def index
@products = Product.all
end
def show
end
def new
@product = Product.new
end
def edit
@product = Product.all
end
def create
@product = Product.new(product_params)
respond_to do |format|
if @product.save
format.html { redirect_to @product, notice: 'Product was successfully created.' }
format.json { render action: 'show', status: :created, location: @product }
else
format.html {
render action: 'new'
}
format.json { render json: @product.errors, status: :unprocessable_entity …Run Code Online (Sandbox Code Playgroud) 我发送一个http请求并获得一个json响应,如下所示:
{"total":"1200.0","used":"35.0","available":1165.0}
Run Code Online (Sandbox Code Playgroud)
现在我想反序列化这个json并在下面的表中向用户显示:
total : 1200
used : 35
availabele : 1165
Run Code Online (Sandbox Code Playgroud)
我用JSON.parse(response),但我得到以下错误:
no implicit conversion of Net::HTTPOK into String
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?