我使用当前版本的 react-boilerplate(使用 webpack)并安装了 Semantic-UI-React,如官方文档http://react.semantic-ui.com/usage 中所述
当我启动服务器时,我得到:
Server started ! ?
Access URLs:
-----------------------------------
Localhost: http://localhost:3000
LAN: http://192.168.100.103:3000
-----------------------------------
Press CTRL-C to stop
webpack built dba595efb772df0727e8 in 11657ms
ERROR in ./semantic/dist/semantic.min.css
Module parse failed: /Users/standardnerd/development/template/semantic/dist/semantic.min.css Unexpected character '@' (11:0)
You may need an appropriate loader to handle this file type.
| *
| */
| @import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic&subset=latin);/*!
| * # Semantic UI 2.2.7 - Reset
| * http://github.com/semantic-org/semantic-ui/
@ ./app/app.js 20:0-43
@ multi main
Run Code Online (Sandbox Code Playgroud)
我需要什么样的“合适的装载机”?
解析器不喜欢 /semantic/dist/semantic.min.css 中的 @import 语句: …
我已经尝试过其他几个类似的帖子,但我仍然收到错误.
在Posts模型中,我有一个category_id字段.我有以下型号:
#Posts model
belongs_to :categories
#Category model
has_many :posts
Run Code Online (Sandbox Code Playgroud)
在Posts索引控制器中,我有:
@categories = @posts.Category.find(:all, :order => 'categoryname')
Run Code Online (Sandbox Code Playgroud)
在视图我有:
<% @posts.each do |post| %>
<tr>
<td><%= post.category_id %></td>
<td><%= @categories.categoryname %></td>
<td><%= link_to 'View', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
</tr>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在第二列中,我尝试显示Category表中的类别名称("categoryname"),而不是posts表中的category_id.我收到一个错误:
#ActiveRecord :: Relation:0x3e1a9b0>的未定义方法`Category'
我也尝试过:
<td><%= post.categories.categoryname %></td>
Run Code Online (Sandbox Code Playgroud)
但得到同样的错误.
以及:
<td><%= post.category.categoryname %></td>
Run Code Online (Sandbox Code Playgroud)
任何建议将不胜感激.
如何检查数组的元素是否仅包含数字(整数)?
describe "#draw" do
it "returns an array" do
expect(@lottery_tip.draw).to be_a_kind_of Array
end
it "has six elements" do
expect(@lottery_tip.draw.count).to eq(6)
end
it "s elements are only numbers" do
expect(@lottery_tip.draw).to ???
end
end
Run Code Online (Sandbox Code Playgroud)
我的简单 LotteryTip 类有效,但我想知道如何检查返回数组中元素的类型...
我将Rails 4与Rails-i18n Gem一起使用,我想用我的语言翻译文件中的占位符替换我的硬编码字符串"300px",如config/locales/de.yml中的%{minimum_resolution}
activerecord:
errors:
models:
organisation:
attributes:
image:
resolution_too_small:"Image Resolution should be at least %{minimum_resolution}"
Run Code Online (Sandbox Code Playgroud)
%{minimum_resolution}中的值应来自app/models/organisation.rb中的自定义验证
def validate_minimum_image_dimensions
if image.present?
logo = MiniMagick::Image.open(image.path)
minimum_resolution = 300
unless logo[:width] > minimum_resolution || logo[:height] > minimum_resolution
errors.add :image, :minimum_image_size
end
else
return false
end
end
Run Code Online (Sandbox Code Playgroud)
如何从minimum_resolution获取值到我的yaml文件中?
我需要在我的HAML代码中使用这种结构:
- if @organisation.type == 'Company'
%p
%strong Number of Employees:
= @organisation.number_of_employees
- elsif @organisation.type == 'EducationalInstitution'
%p
%strong Number of Students
= @organisation.number_of_students
Run Code Online (Sandbox Code Playgroud)
但我得到一个语法错误:得到"elsif"没有前面的"如果"我如何更新我的代码来解决错误?
我有一个PagesController指定了布局'pages.html.erb'.
class PagesController < Spree::StoreController
layout 'pages'
respond_to :html
def lifestyle
render 'lifestyle'
end
def co_step_1
render 'co_step_1'
end
def co_step_2
render 'co_step_2'
end
end
Run Code Online (Sandbox Code Playgroud)
是否可以在PagesController中使用另一种使用不同布局的方法?换句话说,我想覆盖layout 'pages.html.erb'另一种方法.
为什么普通Javascript的这个简单示例减少不起作用?
// expected output: ["red", "yellow", "blue"]
var primaryColors = [
{ color: 'red' },
{ color: 'yellow' },
{ color: 'blue' }
];
primaryColors.reduce({
function(previous, primaryColor) {
previous.push(primaryColor.color);
return previous;
}
}, []);
// VM607:2 Uncaught TypeError: #<Object> is not a function
// at Array.reduce (native)
// at <anonymous>:2:15
Run Code Online (Sandbox Code Playgroud) 作为练习,我正在尝试将地图示例转换为使用reduce:
const numbers = [1, 2, 3, 4];
numbers.map(function(a,b) {
return a+b;
});
// [1, 3, 5, 7]
Run Code Online (Sandbox Code Playgroud)
我尝试使用reduce的相同示例:
numbers.reduce(
(sum, elem) => {
sum.push(elem + elem); // how can one add the index of array to the number instead of doubling it?
return sum;
}, []);
// [2, 4, 6, 8], instead I want: [1, 3, 5, 7]
Run Code Online (Sandbox Code Playgroud) 我有一个包含一个或多个对象的数组,我想过滤掉所有null属性:
asset = [{"ObjId":177791,"ObjCreditlineM":"DEU","ObjReprorechtM":null,"ObjKommentarM":null,"ObjZustandM":null,"ObjReserve01M":null,"ObjReserve02M":null,"ObjFeld01M":null,"ObjFeld02M":null,"ObjFeld03M":null,"ObjFeld04M":"Foto","ObjFeld05M":null,"ObjFeld06M":null,"ObjFeld07M":null,"ObjFeld01S":null,"ObjFeld02S":null,"ObjFeld03S":null,"ObjFeld04S":null,"ObjFeld05S":null,"ObjFeld06S":null,"ObjFeld07S":null,"ObjFeld01F":0,"ObjFeld02F":0,"ObjFeld01D":null,"ObjFeld02D":null,"ObjInv01S":null,"ObjInv02S":null,"ObjInv03S":null,"ObjInv04S":null,"ObjInv05S":null,"ObjInv06S":null,"ObjDinId":0,"ObjReferenz01Id":null,"ObjReferenz02Id":null,"ObjTransferId":null,"ObjGesperrtS":null,"ObjIconTextM":null}]
// My attempt:
var filledProps = asset.map(el => {
if (Object.keys(el)) { // check if object property value is not null
return el;
};
});
console.log(filledProps);Run Code Online (Sandbox Code Playgroud)
但是我又得到了相同的对象属性。我想念什么?
我有一个React组件帖子:
import React, { Component } from 'react';
const list = [
{
title: 'React',
url: 'https://facebook.github.io/react',
author: 'Adam Beat',
num_comments: 4,
points: 3,
objectID: 10,
}, {
title: 'Rails',
url: 'https://www.rubyonrails.org',
author: 'DHH',
num_comments: 8,
points: 4,
objectID: 11,
}
]
class Posts extends Component {
constructor(props) {
super(props); // call the constructor of the extended class
this.state = { // bound state with the this object
list: list,
};
this.onDismiss = this.onDismiss.bind(this);
}
onDismiss(id) {
// const isNotId …Run Code Online (Sandbox Code Playgroud) javascript ×3
activerecord ×1
haml ×1
rails-i18n ×1
reactjs ×1
rspec ×1
semantic-ui ×1
webpack ×1