最近升级到OSX Mavericks已经破坏了我的Rails应用程序的数据库连接.
当我尝试从数据库中提取时,服务器返回以下错误:
PG::ConnectionBad (could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
Run Code Online (Sandbox Code Playgroud)
当psql我试着跑步时,我得到:
psql: could not connect to server: No …Run Code Online (Sandbox Code Playgroud) 我有以下型号:
class Section < ActiveRecord::Base
belongs_to :page
has_many :revisions, :class_name => 'SectionRevision', :foreign_key => 'section_id'
has_many :references
has_many :revisions, :class_name => 'SectionRevision',
:foreign_key => 'section_id'
delegate :position, to: :current_revision
def current_revision
self.revisions.order('created_at DESC').first
end
end
Run Code Online (Sandbox Code Playgroud)
current_revision最近创建的位置在哪里revision.有可能current_revision变成一个关联,所以我可以执行查询Section.where("current_revision.parent_section_id = '1'")吗?或者我应该current_revision在我的数据库中添加一列而不是尝试虚拟地或通过关联创建它?
我试着在jQuery中获取元素标记名称.
我有以下html:
<div class="section" id="New_Revision">
<h1>New Revision <img alt="Lock_closed" class="edit" data-id="1" src="/assets/lock_closed.svg" /></h1>
<p>This is a test paragraph.</p>
<ol class="references">
<li>test</li>
</ol>
</div>
Run Code Online (Sandbox Code Playgroud)
和javascript:
$(".edit").click(function(){
$(this).closest("div.section").children().each(function(){
alert($(this).tagName + " - " + $(this).html());
});
})
Run Code Online (Sandbox Code Playgroud)
我试过$(this).tagName,$(this).nodeName并$(this).attr("tag")在这个问题指出:可提供的jQuery标签的名字吗?
但我总是得到undefined回报.在html()正常输出.为什么我不能获得每个元素的标记名称?
我有以下代码:
$(document).on('keyup', 'p[contenteditable="true"]', function(e) {
if(e.which == 13) {
e.preventDefault();
$(this).after('<p contenteditable = "true"></p>');
$(this).next('p').focus();
} else if((e.which == 8 || e.which == 46) && $(this).text() == "") {
e.preventDefault();
alert("Should remove element.");
$(this).remove();
$(this).previous('p').focus();
};
});
Run Code Online (Sandbox Code Playgroud)
我想在按下某个键时阻止默认操作.preventDefault适用keypress但不适用keyup.有没有办法防止违法行为$(document).on('keyup')?
我link_to在我的调用update我的控制器中的动作:
<%= link_to((image_tag("lock_closed.svg", :class => "edit")), :controller => "sections", :action => "update",:id => section.id, :remote => true) %>
但我真的想update通过一些普通的图像标签来调用这个动作.
所以类似于:
<%= image_tag("lock_closed.svg", :class => "edit")%>
和:
$(".edit").click(function(){
if ($(this).hasClass("update")){
// call update action
} else {
//do something else
};
})
Run Code Online (Sandbox Code Playgroud)
是否可以通过这种方式调用动作?我一直在使用GET&POST或Ajax方法,但我不知道如何利用它们来定位特定的控制器和动作.
我试图使用箭头键遍历contenteditable段落.我不能在所有段落中放置一个包含div,因为它可能被其他不可编辑的元素划分.
我需要能够确定第一行的字符长度,以便当光标在行上时按下向上箭头键,然后它将跳到上一段 - 希望保持光标相对于行的位置.
我可以用以下方法获取游标索引:
function cursorIndex() {
return window.getSelection().getRangeAt(0).startOffset;
}
Run Code Online (Sandbox Code Playgroud)
并将其设置为:在此处找到 - Javascript Contenteditable - 将Cursor/Caret设置为索引
var setSelectionRange = function(element, start, end) {
var rng = document.createRange(),
sel = getSelection(),
n, o = 0,
tw = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null, null);
while (n = tw.nextNode()) {
o += n.nodeValue.length;
if (o > start) {
rng.setStart(n, n.nodeValue.length + start - o);
start = Infinity;
}
if (o >= end) {
rng.setEnd(n, n.nodeValue.length + end - o);
break;
}
}
sel.removeAllRanges();
sel.addRange(rng); …Run Code Online (Sandbox Code Playgroud) 我正在尝试按照如何在GraphQL上的本教程设置一个graphcool订阅/ websockets,但收到以下消息:
WebSocket与“ wss://subscriptions.graph.cool/v1/###”的连接失败:WebSocket在建立连接之前已关闭。
我似乎已经按照教程掌握了所有内容。您知道为什么未建立websockets连接吗?
index.js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/App'
import registerServiceWorker from './registerServiceWorker'
import './styles/index.css'
import { ApolloProvider, createNetworkInterface, ApolloClient } from 'react-apollo'
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws'
import { BrowserRouter } from 'react-router-dom'
import { GC_AUTH_TOKEN } from './constants'
const networkInterface = createNetworkInterface({
uri: 'https://api.graph.cool/simple/v1/###'
})
const wsClient = new SubscriptionClient('wss://subscriptions.graph.cool/v1/###', {
reconnect: true,
connectionParams: {
authToken: localStorage.getItem(GC_AUTH_TOKEN),
}
})
const networkInterfaceWithSubscriptions = addGraphQLSubscriptions(
networkInterface,
wsClient …Run Code Online (Sandbox Code Playgroud)我有一个Page包含许多Section模型的模型,它与一个SectionRevision通过相关联current_revision.从Page模型我想选择所有Sections在current_revision.parent_section_id不为零.
Section 模型:
class Section < ActiveRecord::Base
belongs_to :page
has_many :revisions, :class_name => 'SectionRevision', :foreign_key => 'section_id'
has_many :references
has_many :revisions, :class_name => 'SectionRevision',
:foreign_key => 'section_id'
belongs_to :current_revision, :class_name => 'SectionRevision', :foreign_key => 'current_revision_id'
delegate :position, to: :current_revision
def set_current_revision
self.current_revision = self.revisions.order('created_at DESC').first
end
def children
Section.includes(:current_revision).where(:section_revisions => {:parent_section_id => self.id})
end
end
Run Code Online (Sandbox Code Playgroud)
和Page型号:
class Page < ActiveRecord::Base
belongs_to :parent, :class_name => …Run Code Online (Sandbox Code Playgroud) 我将如何修改它(如何在contenteditable元素(div)中设置插入符号(光标)?)所以它接受一个数字索引和元素并将光标位置设置为该索引?
例如:如果我有段落:
<p contenteditable="true">This is a paragraph.</p>
Run Code Online (Sandbox Code Playgroud)
我打电话给:
setCaret($(this).get(0), 3)
Run Code Online (Sandbox Code Playgroud)
光标将移动到索引3,如下所示:
Thi|s is a paragraph.
Run Code Online (Sandbox Code Playgroud)
我有这个,但没有运气:
function setCaret(contentEditableElement, index)
{
var range,selection;
if(document.createRange)//Firefox, Chrome, Opera, Safari, IE 9+
{
range = document.createRange();//Create a range (a range is a like the selection but invisible)
range.setStart(contentEditableElement,index);
range.collapse(true);
selection = window.getSelection();//get the selection object (allows you to change selection)
selection.removeAllRanges();//remove any selections already made
selection.addRange(range);//make the range you have just created the visible selection
}
else if(document.selection)//IE 8 and lower
{ …Run Code Online (Sandbox Code Playgroud) 我试图在悬停时将图像从50%灰度滤镜转换为无滤镜状态.
但转换在Firefox中不起作用.是否有可能只使用css在firefox中运行转换?
img {
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'saturate\' values=\'0.5\'/></filter></svg>#grayscale"); /* Firefox 3.5+ */
filter: gray alpha(opacity=50); /* IE6-9 */
-webkit-filter: grayscale(50%); /* Chrome 19+ & Safari 6+ */
-webkit-transition: all .6s ease; /* Fade to color for Chrome and Safari */
-moz-transition: all .6s ease;
-ms-transition: all .6s ease;
transition: all .6s ease;
-webkit-backface-visibility: hidden; /* Fix for transition flickering */
}
img:hover {
filter: none;
-webkit-filter: grayscale(0);
}
Run Code Online (Sandbox Code Playgroud) javascript ×4
jquery ×4
associations ×2
activerecord ×1
ajax ×1
apollo ×1
css ×1
firefox ×1
graphcool ×1
html ×1
macos ×1
model ×1
postgresql ×1
ruby ×1
svg ×1
svg-filters ×1
tags ×1