我是Ruby的新手。我在重新启动控制台时遇到问题。我创建了我的应用程序(JacksApp)并为其创建了模型。然后,我关闭了试图再次启动控制台的应用程序。当我输入“ rails c”时,我得到以下信息:
通过Spring预加载器在过程81129中运行加载开发环境(Rails 5.0.0.1)终端类型“ 1.0.0 / libexec:/Users/johnseabolt/.rbenv/shims:/Library/Frameworks/Python.framework/Versions/3.5没有任何条目/ bin:/ usr / local / bin:/ usr / bin:/ bin:/ usr / sbin:/ sbin“; 使用哑终端设置。irb(main):001:0>
我不明白发生了什么。有人可以帮忙吗?我在该应用程序的目录中。我糊涂了。
我仍处于学习 Angular 4 和 Redux 的早期阶段。我有一个从商店获取信息的组件。它在视图中工作正常。但是当我尝试从组件内部访问相同的信息时,我得到的是一个对象而不是值。
这是我的组件:
import { Component } from '@angular/core';
import { NgRedux, select } from 'ng2-redux';
import { AppState } from '../../reducers/reducer';
import { QuizService } from '../../services/quiz.service';
import { clearQuiz } from '../../actions/actions';
@Component({
selector: 'quiz',
templateUrl: './quiz.component.html',
styleUrls: ['./quiz.component.css']
})
export class Quiz {
constructor(private ngRedux: NgRedux<AppState>, private service: QuizService) {}
@select('currentQuiz') currentQuiz;
@select('quizLength') quizLength;
@select('sessionId') sessionId;
handleClose() {
console.log("CLOSE", this.sessionId )
this.service.deleteSession(this.sessionId)
.subscribe(res => {
this.ngRedux.dispatch(clearQuiz())
})
, error => {
console.error(error);
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试将道具传递给我的样式组件。我正在使用样式组件 npm 依赖项。
import React, { Component } from 'react';
import styled from 'styled-components';
class WidgetContainer extends Component {
render() {
return (
<Wrapper name='widget-container'>
</Wrapper>
);
}
}
const mapStateToProps = state => {
return {
user: state.user,
bannerStatus: true
};
};
export default withRouter(connect(mapStateToProps)(WidgetContainer));
const Wrapper = styled.div`
display: flex;
flex-direction: column;
width: 100%;
min-height: 100vh;
margin: auto;
align-items: center;
justify-content: flex-start;
background: -webkit-linear-gradient(top, rgba(162, 209, 234, 1) 0%, rgba(56, 83, 132, 1) 100%);
padding-top: ${(props) => { …Run Code Online (Sandbox Code Playgroud) 我在React应用程序中有一个相当基本的react组件。我想测试提交表单时状态的“提交”部分从false变为true。并不特别困难。但是酶测试似乎找不到按钮。不确定是否与if / else语句有关。
这是组件:
import React from 'react';
import { connect } from 'react-redux';
import { questionSubmit } from '../actions/users';
import { getCurrentUser, clearMessage } from '../actions/auth';
export class AnswerForm extends React.Component {
constructor(props) {
super(props);
this.state = {
submitted: false
}
}
handleFormSubmit(event) {
event.preventDefault();
this.setState({ submitted: true });
this.props.dispatch(questionSubmit(this.answerInput.value, this.props.currentUsername));
this.answerInput.value = '';
}
handleNextButton() {
this.setState({ submitted: false });
this.props.dispatch(getCurrentUser(this.props.currentUsername))
}
render() {
let nextButton;
let form;
let message = <p>{this.props.message}</p>
if (this.state.submitted) {
nextButton = <button …Run Code Online (Sandbox Code Playgroud) 我有这段代码:
const data = {
x: "Target"
}
let bar = () => {
console.log(this.x)
}
let final = bar.bind(data);
final();
Run Code Online (Sandbox Code Playgroud)
此代码返回undefined.这是相同的代码,但具有非箭头功能:
const data = {
x: "Target"
}
let bar = function(){
console.log(this.x)
}
let final = bar.bind(data);
final();
Run Code Online (Sandbox Code Playgroud)
这段代码有效.我想理解为什么arrow函数保持绑定不起作用.我知道,他们处理这个不同.我知道他们保留了调用它们的原始上下文,在这种情况下不包括x.但它是否也阻止bind()工作?
有没有一种方法可以在不知道组件位于哪个组件的情况下搜索*组件内的内容?我正在开发一个新的代码库,但我很难确定哪些组件是哪些。如果我可以搜索在页面上看到的字符串(例如“请单击此处”)并获取组件/文件结果,那么导航应用程序将变得更加容易。有没有办法在 VS Code 中做到这一点?
我正在尝试创建一个分页的 shopify 产品页面。我正在使用since_id他们的文档中列出的策略:https : //shopify.dev/docs/admin-api/rest/reference/products/product#index-2020-10
使用此端点,如文档中所述:
/products.json?limit=5&since_id=${sinceId}
因为Id是上一页上最后一个产品的ID
分页似乎跳过项目。它似乎没有跳过一定数量的产品。有时它只是一个。其他的最多可达 10 个。
显然,这使得“分页”不起作用。
我知道标题解决方案中的链接。但是想知道是否有人遇到过这个问题since_id?
我在Rails应用程序中的路由遇到麻烦。当我尝试跟随指向new_customer_path的链接时出现此错误:
uninitialized constant CustomersController
Run Code Online (Sandbox Code Playgroud)
这是我要遵循的链接。它在我的电影控制器的“新”页面上。这是“新”页面的相关部分:
<div class="row">
<div class="col-xs-12">
<hr />
<%= link_to "Add Customer", new_customer_path, class: 'white' %>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
客户总监:
class CustomerController < ApplicationController
def new
@customer = Customer.new
end
def create
@customer = Customer.new(customer_params)
if @customer.save
redirect_to new_customer_path
end
end
private
def customer_params
params.require(:customer).permit(:fname, :lname, :telephone, :email)
end
end
Run Code Online (Sandbox Code Playgroud)
路线:
Rails.application.routes.draw do
resources :customers
resources :movies do
resources :rentals
end
root 'movies#new'
end
Run Code Online (Sandbox Code Playgroud)
客户模型:
class Customer < ApplicationRecord
has_many :rentals
end
Run Code Online (Sandbox Code Playgroud)
任何想法/提示将不胜感激!
我正在尝试创建一个基本的JavaScript下拉菜单.我正在切换一个名为"show"的类,它显示下拉内容.它不起作用 - 即使在应用类之后元素仍保持隐藏状态.
我想我在这里有一个错误,但我似乎无法找到它.救命!
function drop() {
document.getElementById('content').classList.toggle('show');
}Run Code Online (Sandbox Code Playgroud)
.container {
display: inline-block;
position: relative;
}
.dropdown_btn {
color: white;
background-color: black;
cursor: pointer;
padding: 20px;
}
.dropdown_btn:hover, .dropdown_btn:focus {
background-color: grey;
}
#content {
display: none;
position: absolute;
background: grey;
color: white;
width: 160px;
}
.container a {
text-decoration: none;
display: block;
padding: 10px;
color: white;
}
.container a:hover {
background-color: #f1f1f1
}
.show {
display: block;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<button class="dropdown_btn" onclick="drop()">Menu</button>
<div id="content">
<a href="">Link 1</a>
<a …Run Code Online (Sandbox Code Playgroud)我正在阅读Zed Shaw的Ruby入门书.我遇到了一段我不太了解的代码.
class Person
def initialize(name)
@name = name
@pet = nil
end
attr_accessor :pet
end
class Employee < Person
def initialize(name, salary)
super(name)
@salary = salary
end
attr_accessor :salary, :name
end
Run Code Online (Sandbox Code Playgroud)
我非常粗略地理解超级(名称)部分.我相信这意味着它会延伸到父类?我不确定我理解为什么在现实世界中会这样做.为什么有人会超级(姓名)而不是只写@name = name?
我还在学习.提前致谢!
我有一个 HTML 字符串。它可以是任意数量的元素。我想删除任何包含字体大小的内联样式。
例如:
`<p><span style="font-size: 24px;">ORDER</span></p>`
Run Code Online (Sandbox Code Playgroud)
我需要那个字体大小。我不太清楚如何使用 javascript 正则表达式来做到这一点。我可以寻求帮助吗?