我正在使用富文本编辑器(CKEditor),我有机会让用户创建显示给其他用户的配置文件.
当我将它们显示为以下时,CKEditor可以控制的许多属性都会丢失:
<%= sanitize(profile.body) %>
Run Code Online (Sandbox Code Playgroud)
我的问题是:允许解析属性'style'是否安全?这将允许显示诸如文本颜色,大小,背景颜色,居中,缩进等的事物.我只是想确定它不允许黑客访问我不知道的东西!
我的系统中有用户可以选择"休眠",此时他们可以完全从系统中删除自己和所有相关记录.我在我的网站上查询了在User表及其相关表中的搜索(由多达5个中间表分隔),并且没有明确测试用户是否正在休眠.
有没有办法将用户设置重新定义为非休眠用户,所以我当前的所有查询都可以在不单独更改的情况下工作?
我怎样才能最优雅地完成我想要做的事情?
我有一个模型将图像和pdf上传到Amazon S3 - 图像工作,pdf没有.
这就是我的模型:
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png', 'image/gif']
has_attached_file :pdf,
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:path => "/userpdfs/:id/:basename.:extension"
has_attached_file :photo,
:styles => {:medium => "200x300>", :thumb => "100x150>" },
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:path => "/userphotos/:style/:id/:basename.:extension"
Run Code Online (Sandbox Code Playgroud)
亚马逊正在展示userphotos但没有userpdfs.两种类型在我的数据库中都有四个字段:
pdf_name
pdf_type # could also be a word doc
pdf_size
pdf_updated_at
Run Code Online (Sandbox Code Playgroud)
将任何图像上传到:pdf字段都可以!关于pdfs本身的一些东西似乎搞乱了系统.我的服务器说它已将文件保存到S3但它们没有出现在目录中.
PDF现在只有在标题中没有空格时才起作用.有了空格,我收到以下错误:Errno::EPIPE: Broken Pipe.
我在Github几乎是一个近乎完美的初学者所以请用这个基本问题来幽默我.
我有一台笔记本电脑,我一直用它与Github上的回购交互.我刚买了一台Mac,我想在两台机器上进行编程.
我在新机器上安装了Git,并在终端上设置了用户名,电子邮件和Github令牌.
我需要做的基本命令是什么:
git pull git@github.com/sscirrus/repo.git产品fatal: not a repository (or any of the parent directories): .git.git add .,并git push用密码输入?我正在阅读关于Git的教程,但只是想在我的新手搞砸了许多以前的工作之前确保我正在为我的情况做一些明智的事情.谢谢!
I have recently changed my programming machine, which is leading to some startup issues in getting my new coding source to integrate seamlessly with my existing Github repo and my app on Heroku.
I originally used git clone to clone the Github repo onto my new machine. Since then, something has happened.
git add ., git commit -m "mychanges", and git push, the code gets sent straight to Heroku. It used to get sent …我在使用数据库时遇到了麻烦seed.rb,特别是在表关系方面.
以下是代码示例:
# seed.rb
user = User.find_or_create_by_login(
:login => "myname",
:email => "myname@gmail.com",
:user_type => "Admin",
:password => "admin",
:password_confirmation => "admin")
project = Project.find_or_create_by_user_id(
:user_id => user.id,
:name => "Test Project")
Run Code Online (Sandbox Code Playgroud)
创建项目时(以及我从上面遗漏的其他无关参数),user_id为空.我怎样才能让它发挥作用?
这是我在一些如此简单的事情中看到的最奇怪的行为.在我的种子文件中,我创建了大约八个表,一些表嵌套了3-4个级别(即用户has_many项目;项目has_many任务等).
当我user如上所述呼叫用户并user.id在此之后多次引用时,它只能工作一次!我尝试在创建每条新记录之前添加[user.reload]但无济于事.我不认为这对任何人都有意义,但这里有什么可能吗?谢谢大家.
有没有一种简单的方法将以下逻辑应用于Rails中的字符串?
if string does NOT end with '.' then add '.'
if string does NOT begin with 'http://' then add 'http://'.
Run Code Online (Sandbox Code Playgroud)
当然,有人可能会这样做:
string[0..6] == 'http://' ? nil : (string = 'http://' + string)
Run Code Online (Sandbox Code Playgroud)
但它有点笨重,它会错过https://替代方案.是否有更好的Rails方法来做到这一点?
我已经开始将Omniauth 1.0集成到我的Rails/Authlogic应用程序中,当我尝试访问时出现路由错误localhost:3000/auth/facebook.
我们是否应该为/auth/strategy我们想要的每个人创建一个自定义路线,或者这里有其他错误吗?
# gemfile
gem 'omniauth-facebook'
# routes
resources :authentications
match '/auth/:provider/callback' => 'authentications#create'
# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, '20...', 'bc...'
end
# accessing /auth/facebook
No route matches "/oauth/authorize"
Run Code Online (Sandbox Code Playgroud) 我有点晚来参加git派对,我有一个简单的问题.
我在开发中有三个功能实验,目前在我的主分支上.这些功能可以称为postits,auth和uploads.
当我git status在我的主分支上进行操作时,我得到了"已更改但未更新"的约10个条目以及"未跟踪文件"中的~15个条目的列表.所有这些条目属于三个特征实验之一.
如何将这些条目移动到三个新功能分支中,以便我可以再次使用干净的工作目录?
我想从用户输入一个textarea值的人名,并将它们分成数组中的项目.
从理论上可能的输入:
people = "Abby Andrews, Ben \r\nCharlie Connors Daphne D., Ernie E. Engels; Faye\r\n\r\nGary Gomez"
array = people.split('??')
Run Code Online (Sandbox Code Playgroud)
如何构建正则表达式以成功分裂像上面这样的疯狂链?
应分开:
\r,\n,\r\n,)或分号(;)不应拆分:
我尝试过people.split(/\r\n,;/),people.split(/,;\r\n/)以及它们的组合,但没有产生结果.