protect_from_forgery with: :exception工作怎么样?
我想编辑代码来查看它并从中学习.但是,我无法找到更高级别的抽象位置.
如果您访问http://ccvideofinder.heroku.com/,这是我所指的一个很好的例子.
如何在Rails中完成?我在考虑使用case/ when语句,但是在与IRB搞砸了一段时间之后,我无法理解它.
在模型中:
class Movies < ActiveRecord::Base
validates_presence_of :title
def self.find_by_first_letter(letter)
find(:all, :conditions => ['title LIKE ?', "#{letter}%"], :order => 'title ASC')
end
end
Run Code Online (Sandbox Code Playgroud)
在控制器中:
@result = Movie.find_by_first_letter(params[:letter])
Run Code Online (Sandbox Code Playgroud) 我的应用程序的同一方面有两个问题,抽象视图是这样的:
该应用程序允许用户查看不同的视频剪辑。在后端/管理部分,管理员可以跟踪任何特定剪辑组的视图。例如,管理员可以选择Universal Studios,选择 adate range: Beginning Date: 2015-01-1, End Date: 2016-01-1并点击filter,然后查看Universal在此范围内收到的总观看次数。
问题是,一方面,日期选择器不再工作,所以当我点击日期字段时,没有日历出现,我必须手动输入日期。对于两个,我只得到最远的结果:2015-10-18和2016-02-18。当我输入2015-09-18或之前输入任何内容时,它不会生成结果。
以下是我在 Chorme 中单击检查元素时的错误,
错误:未捕获的类型错误:无法读取未定义的属性“应用”
*/
(function($) {
var _datepicker = jQuery.fn.datepicker;
$.fn.datepicker = function(options) {
var $date = _datepicker.apply(this, arguments); <--- this line
Run Code Online (Sandbox Code Playgroud)
application.js 需要
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory …Run Code Online (Sandbox Code Playgroud) 我尝试过以下操作:
<%= current_user.first_name %>
<%= current_user.last_name %>
<span class="bubble">
<%= best_in_place current_user,
:blurb,
type: :textarea,
:cols => "30",
:rows => "50",
:inner_class => 'occupation-edit',
nil: 'Add a short blurb (max 140)'
%>
</span>
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.是否可以使文本区域更长,如垂直长度?看起来它不能用'best_in_place'宝石定制.
我想允许我的应用程序允许上传 .vtt 文件。现在它只接受 .txt 文件,但我想为字幕添加 .vtt 功能。
我试过这个 * 没有运气:
validates_attachment_content_type :caption,
:content_type => ['application/txt', 'text/plain', 'WEBVTT', 'application/vtt', 'vtt']
Run Code Online (Sandbox Code Playgroud)
在这种情况下,正确的格式是什么?
所以我在我的用户模型上有一个性别列,它当前是一个字符串,我想把它改成一个整数并使其成为男'1',女'0'因为它现在是男性"M"女性"F".运行此迁移时:
class ChangeGenderToIntegerOnUser < ActiveRecord::Migration
def change
change_column :users, :gender, 'integer USING CAST(gender AS integer)'
end
end
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
错误信息:
PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: "M"
: ALTER TABLE "users" ALTER COLUMN "gender" TYPE integer USING CAST(gender AS integer)/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `exec'
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能将性别正确地改为整数?
提前致谢!
因此,在我的应用中,用户可以将图像上传到他们的博客.现在,当他们选择文件时,我想立即显示上传图像的缩略图,以便他们知道在按下表单上的"提交"之前他们选择了哪个图像.
我怎么能这样做?
这是我目前的代码:
<hr>
<h4>Name your blog<br />
& upload an image for it</h4><br />
<%= f.text_field :name, class: "blog-name", placeholder: "Name it here" %><br />
<%= f.file_field :image %>
----> I'd like to show the image here, instantly <----
<%= f.submit "Next", class: "next-button" %>
<br><br>
</div>
<% end %>
Run Code Online (Sandbox Code Playgroud) 我刚刚更新到最新的Mac OS Maverick,现在当在终端中打开应用程序时,我会点击以下消息.关于如何解决这个问题的任何想法?Thx提前!
未安装ruby-2.0.0-p247.
要安装do:'rvm install ruby-2.0.0-p247'
[app]$rvm install ruby-2.0.0-p247
Warning! PATH is not properly set up, '/usr/local/rvm/gems/ruby-2.0.0-p195/bin' is not at first place usually this is caused by shell initialization files - check them for 'PATH=...' entries, it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.0.0-p195'.
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.9/x86_64/ruby-2.0.0-p247.
Continuing with compilation. …Run Code Online (Sandbox Code Playgroud) 所以,我正在使用Figaro存储我的秘密推特和Facebook oauth密钥,以便我可以正确地部署到Heroku.我想确认我做得对.
在我的application.yml(由figaro生成):
// Add application configuration variables here, as shown below.
//
// PUSHER_APP_ID: "2954"
// PUSHER_KEY: 7381a978f7dd7f9a1117
// PUSHER_SECRET: abdc3b896a0ffb85d373
// STRIPE_API_KEY: EdAvEPVEC3LuaTg5Q3z6WbDVqZlcBQ8Z
// STRIPE_PUBLIC_KEY: pk_BRgD57O8fHja9HxduJUszhef6jCyS
// note these are arbitrary keys for the stack overflow
FR_FACEBOOK_KEY=1231231233123123
FR_FACEBOOK_SECRET=3123123123123
TWITTER_CONSUMER_KEY=12312312312312
TWITTER_CONSUMER_SECRET=1312312312312
Run Code Online (Sandbox Code Playgroud)
那就是application.yml,那么我只需要运行:
heroku config:add FR_FACEBOOK_KEY=8926 // and so on...
Run Code Online (Sandbox Code Playgroud)
正确?
或者我错过了什么?
提前致谢!
当我运行rake figaro:heroku我收到此错误:
[new_work]$rake figaro:heroku
rake aborted!
undefined method `reject' for #<String:0x007fbdc6c0e2a8>
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/figaro-0.7.0/lib/figaro.rb:39:in `flatten'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/figaro-0.7.0/lib/figaro.rb:17:in `env'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/figaro-0.7.0/lib/figaro/railtie.rb:7:in `block in <class:Railtie>'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0.rc1/lib/active_support/lazy_load_hooks.rb:36:in `call'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0.rc1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0.rc1/lib/active_support/lazy_load_hooks.rb:45:in `block …Run Code Online (Sandbox Code Playgroud) facebook ruby-on-rails heroku ruby-on-rails-3 ruby-on-rails-4
例如,在一行中,将有2种不同的字体用于不同的单词.
即
(typeworthy) This is a (helvetica) test
Run Code Online (Sandbox Code Playgroud)
值得一提的是'这是一个'和helvetica正在'测试'.虽然不知道如何做到这一点 - 我尝试过使用不同的div类,但是这些文字放在不同的行上.
可以这样做吗?
更新:
视图:
<span class="font1">We</span> <span class="font2">LOVE</span>
<span class="font3">Flappy Bird</span><span class="fontone">so much<div id="space">we made <span class="fonttwo">FLAPPY</span>, the toy game controller!</span></div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.font1{
font-family: 'boxyfont';
text-shadow: -1px -1px white, -1px 1px white, 2px -1px white, -1px -1px white;
margin-top:10px;
display:block;
float:left;
}
.font2{
font-family: 'noteworthy';
padding: 4px 10px 4px 10px;
color: white;
font-weight: bold;
text-shadow: 1px 0 black, 0 2px black, 2px 0 black, 0 -1px black;
margin-top:-10px;
}
Run Code Online (Sandbox Code Playgroud) ruby ×3
css ×2
content-type ×1
datepicker ×1
facebook ×1
heroku ×1
html ×1
javascript ×1
jquery ×1
paperclip ×1
psql ×1
rvm ×1
webvtt ×1