我最近使用Homebrew在我的Mac上安装了PostGIS(El Capitan 10.11.4,Postgres是9.5.1版),我遵循这些说明 - http://morphocode.com/how-to-install-postgis-on- MAC-OS-X /
当我尝试使用Postgres时
pg_ctl -D /usr/local/var/postgres start
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
$ FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 280) running in data directory "/usr/local/var/postgres"?
Run Code Online (Sandbox Code Playgroud)
所以我花了几个小时研究如何解决这个问题,但无济于事.
值得注意的是,我试图按照超级用户的回答中的建议杀死PID - https://superuser.com/questions/553045/fatal-lock-file-postmaster-pid-already-exists- (在上面的例子中,我跑了kill 208
),但是当我再次尝试启动Postgres时,
我得到了同样的错误,尽管有不同的PID号.我看到一些人建议删除postmaster.pid文件,但我觉得我应该保存它作为最后的手段......
不可否认,我不确定如何解决这个问题的一部分原因是我不太清楚postmaster甚至是什么 - 我只是开始了解所有这些.
通过psql db_name
命令跳转到Postgres数据库工作得很好,这是值得的.
我正在使用Mac,Sierra 10.12.3,我正在尝试通过psql
命令访问PostgreSQL数据库,但它抛出了错误
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/bin/psql
Reason: image not found
Abort trap: 6
Run Code Online (Sandbox Code Playgroud)
一两天前,我和某人合作,我需要安装pip,所以我跑了brew install pip
,一切都很好.这是我psql
从那时起第一次尝试运行,我不确定这与我的问题有什么关系,但似乎可能因为我没有做任何其他更改.
现在我做了一点侦探工作,发现如果我去了/usr/local/opt/
那里确实有一个readline
指向的别名目录/usr/local/Cellar/readline/7.0.1
(版本7.0.1似乎也在某些时候安装了 - 也许是pip的一部分?也许我错误地做了...)所以它有一定意义,应该抛出原始错误.我将别名更改为指向/usr/local/Cellar/readline/6.3.8
并且错误稍有改变:
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/bin/psql
Reason: no suitable image found. Did find:
/usr/local/opt/readline/lib/libreadline.6.dylib: stat() failed with errno=20
Abort trap: 6
Run Code Online (Sandbox Code Playgroud)
所以我好像在某个地方,但仍然有问题.如果有人能够对解决方案有所了解,我将永远感激不尽.
我正在使用React(版本15.4.2),我正在<ul>
用我的数据库中的查询结果动态填充.我以为我已经在<li>
s上正确设置了'key'属性,但显然我没有 - 当列表呈现时,我得到错误:
警告:li:'key'不是道具.尝试访问它将导致返回"未定义".如果需要在子组件中访问相同的值,则应将其作为不同的prop传递.
这是我的列表的代码:
function UserList(props) {
return(
<ul className="UserList">
{
props.user_list.map((user) => (
<li className="UserListItem" key={user.id}>
<Link to={`/users/${user.id}`}>{user.first_name} {user.last_name}</Link>
</li>
))
}
</ul>
);
}
Run Code Online (Sandbox Code Playgroud)
我看了一下这些文档,在我看来这应该是正确的.如果有人能澄清我的错误,我将不胜感激.
在我的React应用(版本15.5.4)中,对于其中一个组件中的输入字段,我收到以下警告:
Warning: 'value' prop on 'input' should not be null. Consider using the empty string to clear the component or 'undefined' for uncontrolled components.
引用以下jsx:
<label>Description<br />
<input
type="text"
name="description"
value={this.state.group.description}
onChange={this.handleChange}
maxLength="99" />
</label>
Run Code Online (Sandbox Code Playgroud)
但是我对此感到困惑,因为的值this.state.group.description
是""
在构造函数中设置的:
this.state = {
"group": {
"name": "",
"description": ""
}
}
Run Code Online (Sandbox Code Playgroud)
更令我惊讶的是,另一个输入字段引用了this.state.group.name
,但没有引发警告:
<label>Name *<br />
<input
type="text"
name="name"
value={this.state.group.name}
onChange={this.handleChange}
maxLength="99"
required="required"
autoFocus />
</label>
Run Code Online (Sandbox Code Playgroud)
我在这里想念什么吗?据我所知,我已经将这两个值的初始状态设置为空字符串,并在两个输入字段中以相同的方式引用了它们,但是一个抛出警告,一个没有警告。
这不是世界末日……该应用程序运行良好,但我真的很想了解为什么会发生这种情况并使我的应用程序正常运行。
这是handleChange
:
handleChange(event) {
const attribute = event.target.name
const updatedGroup …
Run Code Online (Sandbox Code Playgroud) 我最近在Heroku上部署了一个React/Express应用程序,但我遇到了环境变量的问题,这些环境变量是构建应用程序和Heroku部署管道的一部分 - 简而言之,来自应用程序staging
发行版的环境变量的值是在推广时继续进行production
- 我可以正确设置环境变量的唯一方法是直接推送应用程序production
,这首先实际上违背了部署管道的目的.以下是该场景的摘要:
有问题的环境变量是API_URL
这样引用的webpack.config.js
:
plugins: [
new webpack.DefinePlugin({
'API_URL': JSON.stringify(process.env.API_URL || 'http://localhost:4000/api/v1')
})
]
Run Code Online (Sandbox Code Playgroud)
API本身是另一个带有staging
和production
释放的Heroku应用程序,因此API_URL
环境变量的值在我的React app Heroku配置中分别设置为https://staging-api-12345.herokuapp.com/api/v1
和https://production-api-12345.herokuapp.com/api/v1
.
当我推送我的React应用程序时staging
,它可以完美地运行 - 但是,当我将应用程序升级到production
并首次调用API时,它仍然指向https://staging-api-12345.herokuapp.com/api/v1
.好吧,我理解为什么会这样 - 应用程序是在被推送到staging
... 时构建的.所以我尝试在推广之后重建应用程序production
,但是这不起作用,它仍然使用staging
环境变量.
当使用Heroku部署管道时,是否有办法强制应用程序段重建,以便它将捕获不同的环境变量?
我无法成功运行 Ecto 迁移来删除唯一索引,该索引在最初创建时已提供:name
属性的唯一索引(以便不使用默认索引名称)。但是,我现在无法删除该索引,因为 Ecto 似乎正在尝试查找名称不正确的索引(尽管我已经提供了它)。
唯一索引最初是通过迁移创建的,如下所示:
def change do
create(
unique_index("foo", [:bar_id],
where: "rejected IS NULL AND accepted IS NULL)",
name: :bar_pending_index
)
)
end
Run Code Online (Sandbox Code Playgroud)
当我检查 psql shell 中的表时,我看到该索引列出为:
"bar_pending_index" UNIQUE, btree (bar_id) WHERE rejected IS NULL AND accepted IS NULL
Run Code Online (Sandbox Code Playgroud)
为了删除索引,我编写了以下迁移:
def up do
drop index("foo", [:bar_pending_index])
end
def down do
create(
unique_index("foo", [:bar_id],
where: "rejected IS NULL AND accepted IS NULL)",
name: :bar_pending_index
)
)
end
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行此迁移时,出现错误
14:01:56.573 [info] == Running 20210610173741 MyApp.Repo.Migrations.DropIndex.up/0 forward
14:01:56.576 [info] …
Run Code Online (Sandbox Code Playgroud) 在Elixir中,有没有办法直接从shell调用模块函数,而不需要启动iex -S mix
会话?让我用一个场景来说明:
作为我的Phoenix应用程序的一部分,我编写了一个辅助模块,可以从相邻的iex -S mix
会话中运行.这是一个超级简化的版本:
defmodule MyApp.Helper do
# For the demo, these imports/aliases are not used - but they're there in real life.
import Ecto.Query
alias MyApp.Repo
def start do
{:ok, "Done"}
end
end
Run Code Online (Sandbox Code Playgroud)
如果我启动会话iex -S mix
然后从模块运行一个函数,它一切正常:
$ iex -S mix
Erlang/OTP 20 [erts-9.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Compiling 2 files (.ex)
Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> MyApp.Helper.start
{:ok, …
Run Code Online (Sandbox Code Playgroud) 我的 Rails 表单中有一个选择输入 -
<%= f.select :store_type_id, @storeType.map{ |type| [type.store_type.capitalize, type.id] }, {include_blank: 'Select store type'} %>
Run Code Online (Sandbox Code Playgroud)
我怎样才能使第一个选项(“选择商店类型”)既被禁用又被选择?
我想要的 html 等效项是
<option disabled selected>Select store type</option>
Run Code Online (Sandbox Code Playgroud)
谢谢你!
我正在学习使用Phoenix框架,我正在尝试向控制器操作执行AJAX帖子 - 但是,我遇到了CSRF保护问题.
对于初学者,我没有使用表单 - 只是想将文本从输入传递给控制器:
<input type="text" id="raw-input" />
<button id="send-button">Send it!</button>
<script>
$("#send-button").click(function(){
var input = $("#raw-input").val();
$.ajax({
url: "/test/process",
type: "POST",
dataType: "json",
beforeSend: function(xhr) {xhr.setRequestHeader("X-CSRF-Token", $("meta[name='csrf-token']").attr("content"))},
data: {"input" : input},
success: function(response){
console.log(response);
}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
控制器(不担心做任何事情input
......只是想验证一个成功的帖子!):
def process(conn, %{"input" => input}) do
IO.puts "got it!"
end
Run Code Online (Sandbox Code Playgroud)
和路由器:
post "/test/process", TestController, :process
Run Code Online (Sandbox Code Playgroud)
我几乎解除$.ajax
了Rails应用程序的调用,它工作正常,但它不是在这里做的 - 运行它返回403错误和日志(Plug.CSRFProtection.InvalidCSRFTokenError) invalid CSRF (Cross Site Request Forgery) token, make sure all requests include a valid '_csrf_token' …
在我的React应用程序中,我有一些函数,我希望能够访问几个类似的组件...但是,我想绑定this
到共享函数,以便他们可以做更新组件状态的事情等等...然而,似乎导入函数然后尝试以this
"典型的"React方式绑定不起作用.
以下是我想要完成的内容的说明 - 在这种情况下,单击呈现的按钮将从导入的共享函数文件中调用该函数并更新组件状态:
//shared_functions.js
const sharedFunctions = {
testFunction = () => {
this.setState({functionWasRun: true})
}
}
//MyComponent.jsx
import React, { Component } from 'react';
import sharedFunctions from '../static/scripts/shared_functions.js';
let { testFunction } = sharedFunctions;
class MyComponent extends Component {
constructor(props){
super(props);
this.testFunction = this.testFunction.bind(this)
this.state = {
functionWasRun: false
}
}
render(){
return(
<div>
<button onClick={this.testFunction}>Click</button>
</div>
)
}
}
Run Code Online (Sandbox Code Playgroud)
尝试按原样运行此代码将返回如下错误:
Uncaught (in promise) TypeError: Cannot read property 'bind' of undefined
我得到了所有关于......但我想知道的是:是否可以绑定this
到 …
reactjs ×3
elixir ×2
postgresql ×2
ajax ×1
command-line ×1
ecmascript-6 ×1
ecto ×1
forms ×1
heroku ×1
iex ×1
javascript ×1
postgis ×1
python ×1
shell ×1
webpack ×1