我刚刚意识到我新创建的 Reactjs 应用程序有一个文件src/reportWebVitals.js
,该文件正在 index.js 中被调用。这个文件/代码段的用途是什么?
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;
Run Code Online (Sandbox Code Playgroud) 我有一个很好的运行Rails 4应用程序使用弹性搜索和searchkick.I有geosearch通过设置geo_point它在开发中工作得很好,但在部署相同的代码并验证生产中的索引后,在数字海洋上使用3GB RAM和Ubuntu -16操作系统,它失败了 -
A Searchkick::InvalidQueryError occurred in home#show_by_location_and_event:
[400] {"error":{"root_cause":[{"type":"query_parsing_exception","reason":"failed to find geo_point field [location]","index":"halls_production_20180520121711247","line":1,"col":724}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"halls_production_20180520121711247","node":"Mn7tHSKLQWSB1N8Sypb6Qg","reason":{"type":"query_parsing_exception","reason":"failed to find geo_point field [location]","index":"halls_production_20180520121711247","line":1,"col":724}}]},"status":400}
app/controllers/home_controller.rb:168:in `show_by_location_and_event'
Run Code Online (Sandbox Code Playgroud)
home_controller.rb
lat_lng = Geocoder.coordinates(@location)
@event_name = params[:event_name]
###XXXX FAILING HERE AT BELOW LINE
@halls = Hall.get_completed_halls_only.search @location ,
where: {
location: { near: lat_lng,within: "20km"} ,
workflow_state: "accepted",
active: "true"
}
Run Code Online (Sandbox Code Playgroud)
车型/ hall.rb
##added geo_point
##hall has one address association
searchkick word_start: [:name, :slug, :description, :facebook_link],
word_middle: [:name, :slug, :description, :facebook_link],
text_start: [:name, :slug] …
Run Code Online (Sandbox Code Playgroud) 我有如下所示的方法:
def all_pages_and_its_n_level_child
@parent_pages = Page.where(:parent_id => params[:page_id])
#this will give me all child of this page
for page in @parent_pages
child_exists=Page.where(:parent_id=>page.id)
#this will give all children of that page
#*I want to make this loop further so that i can check to N-levels,
#this is only for two levels*
end
end
Run Code Online (Sandbox Code Playgroud) 我曾经尝试过很多关于Rails垃圾收集器的谷歌,但我没有得到可靠的答案.有没有人有一个来源来展示如何在Rails中实现垃圾收集?我们怎样才能控制它?
我有一个 Rails 6 应用程序,注册用户(所有者)可以在 S3 上上传文件 -图像/视频,然后所有者可以向其他用户(邀请)提供访问权限以查看他们上传的内容。
有没有办法限制文件访问,以便只有所有者才能下载他上传的文件(图像/视频),从而对其他非所有者/受邀用户进行限制。。视频/图像不应该通过右键单击并保存/下载来如此轻松地下载。
注意- 上传的文件还包括大视频(mp4 和 HLS 流),因此其他受邀用户可以查看它们,但无法下载,除非他们是所有者/上传者,因为文件来自 AWS Cloudfront 的视频和 S3(如果他们是)是图像。
协会的设置如下 -
User has one role
User has many images/videos, each residing in his own folder on s3(`bucket/user_id/image_slug/` or `bucket/user_id/video_slug/`)
User has many invitations(must be view only access to owners file)
Run Code Online (Sandbox Code Playgroud)
不确定,什么是正确的方法,可以 -
让我知道最适合这种方法的逻辑是什么。
请帮忙解决问题.
使用回形针我组织了上传图片.有用.
现在我想组织一个视频上传.我改变了这个模型:型号:
class Video < ActiveRecord::Base
validates :title, presence: true
validates :video, presence: true
belongs_to :user
has_attached_file :video,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "/images/:style/missing.png"
validates_attachment_content_type :video, :content_type => /\Avideo\/.*\Z/
validates_attachment_file_name :video, :matches => [/3gp\Z/, /mp4\Z/, /flv\Z/]
validate :file_size_validation, :if => "video?"
def file_size_validation
errors[:video] << "should be less than 2MB" if video.size.to_i > 30.megabytes
end
end
Run Code Online (Sandbox Code Playgroud)
视频控制器:
def create
@video = Video.new(video_params)
if @video.save
@video.update_attributes(user: current_user)
flash[:success] = :video_created
redirect_to @video
else …
Run Code Online (Sandbox Code Playgroud) 我现在主要使用Handlebars JS,但我正在研究JSX.是否有一个等同于Handlebars部分的JSX?我想知道我是否可以创建一些可以在几个不同的JSX视图中重用的标记.
我有一个模型,group_question_answer.rb
class GroupQuestionAnswer < ActiveRecord::Base
belongs_to :group_question
validates_presence_of :answer
validates_presence_of :answer_question
end
Run Code Online (Sandbox Code Playgroud)
对于属性answer
,answer_question
我收到错误消息,因为Group question answers answer can't be blank
我只需要显示answer cant be blank
。我什至尝试添加:message=>"cant be blank"
,但仍然没有得到我需要的消息。我如何删除模型名称,并且可以只显示错误消息....
我正在使用 ruby on Rails 构建一个示例电子商务应用程序。我的控制器名称之一是“products_controller”。该控制器也作为嵌套控制器放置在内部。这些控制器内的操作是相同的。我们如何表示这些操作而不需要重复代码。下面给出了代码示例。
应用程序/控制器/products_controller.rb
def index
@product = Product.all
@vari = @products.variants
.............
.............
end
Run Code Online (Sandbox Code Playgroud)
应用程序/控制器/master_admins/products_controller.rb
def index
@product = Product.all
@vari = @products.variants
.............
.............
end
Run Code Online (Sandbox Code Playgroud)
应用程序/控制器/master_admins/properties_controller.rb
def product
@product = Product.all
@vari = @products.variants
.............
.............
end
Run Code Online (Sandbox Code Playgroud)
上面的动作包含相同的一组代码。我们如何重构它以使代码不重复。
提前致谢....
我有一个UserObserver after_commit
(after_create
为了避免未找到ID的竞争条件错误而更改为)以更新计数。但是我知道对于每个创建,更新都会执行after_commit
代码(我知道会发生)。如何after_commit
在创建时运行唯一的?我的解决方案很少,但有点困惑。我试过了:
after_commit :do_something, :on => :create
在模型中使用。created_at
和updated_at
中的观察者;如果它们相同,那就是新记录。user.new_record?
我很困惑,因为我想使用第三个,但是它不起作用,我也不知道为什么。我只想使用观察者,而不是模型。有什么想法吗?
我是第一次尝试设计。我正在点击链接:https : //github.com/plataformatec/devise。在这里,我已经执行了命令:
rails generate devise MODEL
Run Code Online (Sandbox Code Playgroud)
当我执行这个时,模型和视图部分被创建。当我检查路由时,我注意到有一个名为:MODEL的控制器。但我没有在项目中找到控制器。我的查询是如何我们查找是否生成了控制器并在项目中使用该控制器。提前致谢。
ruby ×3
reactjs ×2
amazon-s3 ×1
aws-sdk-ruby ×1
devise ×1
javascript ×1
jsx ×1
observers ×1
paperclip ×1
refactoring ×1
ruby-2.2 ×1
searchkick ×1
web-vitals ×1