我正在尝试将代码从我的GitHub仓库中提取到我的服务器上,但由于合并冲突,拉动仍然失败.我不想保留自上次拉取以来本地服务器上可能发生的任何更改.
那么有没有办法可以强制Git用GitHub中的任何版本覆盖,而不是打扰我的冲突?
我的应用程序中有一个模态对话框,可以在y方向上相当长.这引入了一个问题,即对话框的某些内容隐藏在页面底部.

我希望窗口滚动条在显示时滚动对话框,并且太长而无法放在屏幕上但是将主体留在模态后面.如果您使用Trello,那么您就知道我想要什么.
这可能不使用JavaScript来控制滚动条吗?
这是我到目前为止应用于我的模态和对话框的CSS:
body.blocked {
overflow: hidden;
}
.modal-screen {
background: #717174;
position: fixed;
overflow: hidden;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0.9;
z-index: 50;
}
.dialog {
background: #fff;
position: fixed;
padding: 12px;
top: 20%;
left: 50%;
z-index: 10000;
border-radius: 5px;
box-shadow: 0, 0, 8px, #111;
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个下载链接,用户应该能够下载存储在s3上的文件.这些文件可以在网址上公开访问,看起来像
https://s3.amazonaws.com/:bucket_name/:path/:to/:file.png
Run Code Online (Sandbox Code Playgroud)
下载链接在我的控制器中执行操作:
class AttachmentsController < ApplicationController
def show
@attachment = Attachment.find(params[:id])
send_file(@attachment.file.url, disposition: 'attachment')
end
end
Run Code Online (Sandbox Code Playgroud)
但是当我尝试下载文件时出现以下错误:
ActionController::MissingFile in AttachmentsController#show
Cannot read file https://s3.amazonaws.com/:bucket_name/:path/:to/:file.png
Rails.root: /Users/user/dev/rails/print
Application Trace | Framework Trace | Full Trace
app/controllers/attachments_controller.rb:9:in `show'
Run Code Online (Sandbox Code Playgroud)
该文件肯定存在,可以在错误消息的URL中公开访问.
如何允许用户下载S3文件?
ruby ruby-on-rails amazon-s3 ruby-on-rails-3 ruby-on-rails-3.2
我有一个rails模型,它有7个数字属性由用户通过表单填写.
我需要验证每个属性的存在,这显然很容易使用
validates :attribute1, :presence => true
validates :attribute2, :presence => true
# and so on through the attributes
Run Code Online (Sandbox Code Playgroud)
但是我还需要运行一个自定义验证器,它接受许多属性并用它们进行一些计算.如果这些计算的结果不在一定范围内,则应将模型声明为无效.
就它而言,这也很容易
validate :calculations_ok?
def calculations_ok?
errors[:base] << "Not within required range" unless within_required_range?
end
def within_required_range?
# check the calculations and return true or false here
end
Run Code Online (Sandbox Code Playgroud)
然而问题是方法"validate"总是在方法"验证"之前运行.这意味着如果用户将其中一个必填字段留空,则rails尝试使用空白属性进行计算时会抛出错误.
那么如何首先检查所有必需属性的存在?
我通过病原体安装了Solarized,它在我的Mac上的终端和MacVim上都运行良好.今天,我尝试在Linode上设置一个Ubuntu盒子.我刚刚克隆了我的dotfiles和符号链接到我.vim和.vimrc文件夹(这与我在本地机器上使用的设置相同.
每当我尝试在Ubuntu盒子上运行vim时,我都会收到错误消息
Error detected while processing /root/.vimrc:
line 43:
E185: Cannot find color scheme solarized
Press ENTER or type command to continue
Run Code Online (Sandbox Code Playgroud)
我可以告诉我.vimrc正在加载,因为所有其他设置如行号都有效.
相关的行.vimrc如下:
" settings needed for solarized colorscheme
syntax enable
set background=dark
let g:solarized_termcolors=256
colorscheme solarized
Run Code Online (Sandbox Code Playgroud)
这是我的.vim/bundle目录的设置(如果你怀疑我实际上没有在那里解决!):
~ ls .vim/bundle
ack coffeescript liquid snipmate vim-colors-solarized vim-jst zencoding
closetag html5.vim nerdtree surround vim-javascript vim-rails
Run Code Online (Sandbox Code Playgroud)
另一件事,echo &t_Co在ubunto盒子上运行vim让我感到高兴256.
有任何想法吗?
我有一个Backbone.js模型,当用户点击模型视图中的链接时,我试图销毁它.视图是这样的(伪代码,因为它是在CoffeeScript中实现的,可以在问题的底部找到).
var window.ListingSaveView = Backbone.View.extend({
events: {
'click a.delete': 'onDestroy'
},
onDestroy: function(event){
event.preventDefault();
this.model.destroy({
success: function(model, response){
console.log "Success";
},
error: function(model, response){
console.log "Error";
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
当我单击delete浏览器中的链接时,Error即使我的服务器记录成功销毁关联的数据库记录并返回200响应,我也总是登录到控制台.当我刷新页面(导致集合从数据库重新渲染)时,我删除的模型将消失.
有趣的是,当我登录response错误回调时,它具有200表示成功的状态代码,但它也报告了statusText: "parseerror"这意味着什么.我的服务器日志中没有错误.
我究竟做错了什么?
这是来自服务器的响应:
Object
abort: function ( statusText ) {
always: function () {
complete: function () {
done: function () {
error: function () {
fail: function () {
getAllResponseHeaders: function () { …Run Code Online (Sandbox Code Playgroud) javascript ruby-on-rails javascript-framework backbone.js ruby-on-rails-3
是否有更短的方法来做到以下(
@user.employees.map { |e| { id: e.id, name: e.name } }
# => [{ id: 1, name: 'Pete' }, { id: 2, name: 'Fred' }]
Run Code Online (Sandbox Code Playgroud)
User has_many雇员.这两个类都继承自ActiveRecord::Base.
我不喜欢上面提到的两件事
有没有更好的办法?
我有一个标准的控制器,它被设置为响应HTML,JS和JSON请求:
def picture
@picture = Picture.new params[:picture]
respond_to do |format|
if @picture.save
format.html do
logger.debug "In the HTML responder"
redirect_to @picture
end
format.json { render json: @picture, status: :created, location: @picture }
format.js { render :nothing => true }
else
# you get the idea
end
end
end
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用该$.ajax函数向该控制器发送请求(我不能:remote => true在这种特定情况下使用 - 我正在尝试使ajax文件上传工作).
$.ajax({
url: $("form#new_picture").attr("action"),
type: "POST",
data: formdata,
processData: false,
contentType: false
});
Run Code Online (Sandbox Code Playgroud)
问题是我的请求由于某种原因被视为HTML请求.如何告诉rails我想要JS响应?
顺便说一句,我在我的项目中使用了jquery_ujs,所以如果有必要,我可以访问它提供的方法.我不是很擅长JS来调整那里做我需要的东西.
我希望覆盖Devise::RegistrationsController实现一些自定义功能.为此,我创建了一个RegistrationsController像这样的新东西:
# /app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def new
super
end
end
Run Code Online (Sandbox Code Playgroud)
并设置我的路线,如下所示:
devise_for :users, :controllers => { :registrations => "registrations" }
Run Code Online (Sandbox Code Playgroud)
并试图像这样测试它:
describe RegistrationsController do
describe "GET 'new'" do
it "should be successful" do
get :new
response.should be_success
end
end
end
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误:
1) RegistrationsController GET 'new' should be successful
Failure/Error: get :new
AbstractController::ActionNotFound:
Could not find devise mapping for path "/users/sign_up".
Maybe you forgot to wrap your route inside the scope block? For example:
devise_scope …Run Code Online (Sandbox Code Playgroud) ruby ×2
vim ×2
activemodel ×1
amazon-s3 ×1
backbone.js ×1
css ×1
devise ×1
git ×1
git-pull ×1
javascript ×1
jquery ×1
routes ×1
routing ×1
scroll ×1
terminal ×1
ubuntu ×1
validation ×1
zsh ×1