我的引导字形显示在其他浏览器上,但我在 google chrome 上收到此错误:
来自源“ http://d37p52igaahgm9.cloudfront.net ”的字体已被跨源资源共享策略阻止加载:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问来源“ http://www.anthonygalli.com ”。
尽管尝试了以下方法,错误仍然存在:
应用程序控制器.rb
before_action :set_cors
def set_cors
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Request-Method'] = '*'
end
Run Code Online (Sandbox Code Playgroud)
应用程序.rb
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
config.action_dispatch.default_headers = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Request-Method' => '*'
}
Run Code Online (Sandbox Code Playgroud)
CORS 配置编辑器
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://www.anthonygalli.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Content-*</AllowedHeader>
<AllowedHeader>Host</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>https://anthonygalli.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Content-*</AllowedHeader>
<AllowedHeader>Host</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)
参考
google-chrome ruby-on-rails amazon-s3 cors amazon-cloudfront
我跟着伟大的Ryan Bates帮我设置了ominauth-facebook,但在他的教程中他只展示了如何使用短期访问令牌(小时或2小时)进行设置.我们如何修改他的教程以使用长期访问令牌(60天)进行设置?
我一直在阅读有关它的Facebook文档和这个旧的SO问题.
这两个链接都建议添加一些这样的代码(尽管代码略有不同):
GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={short-lived-token}
Run Code Online (Sandbox Code Playgroud)
人们会把它添加到哪里?
从我所看到的情况来看,似乎他们正在使它变得非常复杂.有人可以用初学者友好的语言吗?
我的代码与贝茨先生略有不同.
初始化/ ominauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, "1540352575225959", "ee957abf5e851c98574cdfaebb1355f4", {:scope => 'user_about_me'}
end
Run Code Online (Sandbox Code Playgroud)
的routes.rb
get 'auth/:provider/callback', to: 'sessions#facebook'
Run Code Online (Sandbox Code Playgroud)
sessions_controller
def facebook
user = User.from_omniauth(env["omniauth.auth"])
session[:user_id] = user.id
redirect_to root_url
end
Run Code Online (Sandbox Code Playgroud)
user.rb
class User < ActiveRecord::Base
acts_as_tagger
acts_as_taggable
has_many :notifications
has_many :activities
has_many :liked_comments, through: :comment_likes, class_name: 'Comment', source: :liked_comment
has_many :valuation_likes
has_many :habit_likes
has_many :goal_likes
has_many :stat_likes
has_many …Run Code Online (Sandbox Code Playgroud) before_save :date_started_sets_deadline, if date_started.present?
Run Code Online (Sandbox Code Playgroud)
我不希望它before_save运行 if :date_started == nil。我已经尝试了上述行的各种版本,所以不确定是否必须更改它或方法本身。
def date_started_sets_deadline
if self.date_started > Date.tomorrow
self.deadline = self.date_started
end
end
Run Code Online (Sandbox Code Playgroud)
NoMethodError (undefined method '>' for nil:NilClass): app/models/challenge.rb:35:in 'date_started_sets_deadline'每当用户尝试创建挑战时,我都试图避免该错误date_started
选中此框后,如何在单击"保存"时将用户的电子邮件从"输入电子邮件"添加到我的mailchimp订阅者列表中?
用户/ new.html.erb
<%= form_for(@user) do |f| %>
<%= f.email_field :email, placeholder: 'Enter Email' %>
<%= f.check_box ????? %> Get blog posts from Anthony Galli, CEO & Founder about conquering challenges in life & business!
<% end %>
Run Code Online (Sandbox Code Playgroud)
在注册过程之外,人们可以通过在subscribes/subscribe.html.erb中输入他们的电子邮件来订阅.
<!-- MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-081711.css" rel="stylesheet" type="text/css">
<div id="mc_embed_signup">
<form action="//anthonygalli.us8.list-manage.com/subscribe/post?u=3e4b26579d28ecaf37fe444e4&id=3dbb9c5c12" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<input type="email" value="" name="EMAIL" class="required email" placeholder="Enter Email" id="mce-EMAIL">
<input type="text" name="b_3e4b26579d28ecaf37fe444e4_3dbb9c5c12" tabindex="-1" value="">
<input type="submit" value="Save" name="subscribe" …Run Code Online (Sandbox Code Playgroud) 我用 保存一个数字params[:number].gsub(/\D/,''),但我不想去掉加号:+
例如,如果用户保存数字+1 (516) 949-9508,则将其另存为,15169499508但我们如何保留+as +15169499508?
换句话说,如果用户输入例如:
http://0.0.0.0:3000/goals/3
Run Code Online (Sandbox Code Playgroud)
即使用户将其提交为"私人",他们也能够看到该用户的目标.这是我忽略的,因为它通过"私人"提交通过用户的个人资料和订阅源隐藏目标,但是如果其他用户通过网址直接搜索它则不会.
我们该如何解决这个问题?
goals_controller
class GoalsController < ApplicationController
before_action :set_goal, only: [:show, :edit, :update, :destroy, :like, :user_goals]
before_action :logged_in_user, only: [:create, :destroy]
before_action :correct_user, only: [:edit, :update, :destroy]
def index
if params[:tag]
@goals = Goal.tagged_with(params[:tag])
elsif params[:user_id]
@accomplished_goals = User.find(params[:user_id]).goals.accomplished.order("deadline")
@unaccomplished_goals = User.find(params[:user_id]).goals.unaccomplished.order("deadline")
else
@accomplished_goals = current_user.goals.accomplished.order("deadline")
@unaccomplished_goals = current_user.goals.unaccomplished.order("deadline")
end
end
def user_goals
@goals = Goal.find_by({user_id: params[:user_id]})
render :index # or some other view
end
def show
@goal = Goal.find(params[:id])
@commentable = @goal
@comments = @commentable.comments
@comment = …Run Code Online (Sandbox Code Playgroud) 当用户实时输入他们的单词时,如何在 text_area 中标题/大写单词(某些介词除外)?
<%= f.text_area :name %>
Run Code Online (Sandbox Code Playgroud)
例如,要创建与本网站相同的行为:http : //titlecapitalization.com/
当用户单击按钮时...
#featured-challenge-button {
background-color: #446CB3;
box-shadow: 3px 3px 5px black;
&:hover {
background-color: #ccac00;
box-shadow: none;
}
&:active {
background-color: #ccac00;
box-shadow: none;
}
&:focus {
background-color: #ccac00;
box-shadow: none;
}
}
Run Code Online (Sandbox Code Playgroud)
按钮示例:
# link_to
<%= link_to next_challenge_path, class: "btn", id: "featured-challenge-button" do %>
<span class="glyphicon glyphicon-plus"></span>
<% end %>
# submit
<%= button_tag(type: 'submit', class: "btn", id: "featured-challenge-button") do %>
Save
<% end %>
Run Code Online (Sandbox Code Playgroud)
我怎样才能显示它被立即按下?
在浏览器上它可以工作,但在我的 iPhone 上,点击按钮时没有任何影响。单击按钮的唯一指示是屏幕顶部的加载栏。
我使用:active错误还是有另一种 CSS 技术或有 javascript 解决方案?
我不明白为什么开发中的东西有效,但在生产中它有不同的行为,这是我的另一个例子.在此示例中,注释始终由DESC在开发中排序,但在生产中如果用户喜欢注释,则该注释将移动到列表的底部,就像重新创建注释一样.
为什么会这样?
comments_controller
class CommentsController < ApplicationController
before_action :set_commentable, only: [:index, :new, :create]
before_action :set_comment, only: [:edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update, :destroy]
def index
@comments = @commentable.comments.order("created_at DESC")
end
def new
@comment = @commentable.comments.new
end
def create
@comment = @commentable.comments.new(comment_params)
if @comment.save
redirect_to @commentable, notice: "Comment created."
else
render :new
end
end
def edit
end
def update
if @comment.update_attributes(comment_params)
redirect_to :back, notice: "Comment was updated."
else
render :edit
end
end
def destroy
@comment.destroy
redirect_to @comment.commentable, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个条件,其中if @challenge.deadline(是a Date)在上周(即最后7天)内,然后执行x,否则执行y.
我试过了:
if @challenge.deadline < 1.week.ago #2017-03-03 01:52:13 -0500
if @challenge.deadline < 7.days.ago.to_date #2017-03-03
if @challenge.deadline < Date.current-7.days #2017-03-03
# All these come up false since I guess it sees 06 as more than 03, but I want the conditional to be based on date such as 06 is less than 7 days ago and therefore should be true
Run Code Online (Sandbox Code Playgroud)
在这个例子中@challenge.deadline等于2017-03-06
迭代
<% @challenges.with_exact.each do |challenge| %>
etc...
<% end %>
Run Code Online (Sandbox Code Playgroud)
模型范围尝试
scope :with_exact, -> { where("exact == ?", Time.zone.now.hour) } # Error: PG::UndefinedFunction: ERROR: operator does not exist: time without time zone == integer
scope :with_exact, -> { where(exact: Time.zone.now.hour) } # Error: PG::InvalidDatetimeFormat: ERROR: invalid input syntax for type time: "13"
Run Code Online (Sandbox Code Playgroud)
有些挑战会有一个nil确切的。
我如何才能仅在何处迭代挑战 Time.zone.now.strftime('%H') == challenge.exact.strftime('%H')
如何获得,
1 = X
2 = XX
3 = XXX
Run Code Online (Sandbox Code Playgroud)
而不是在索引中显示为数字.正如古老的谚语所说,"3罢工你已经出局!"
这是在索引中:<%= [params[:missed]].flatten.length %>
感谢您的时间!