Tag: ruby on rails 4

如何使用Rails应用程序保存SSL证书并在NGINX中创建虚拟主机?

我有一个Rails应用程序,它使用gem Rails Let’s Encrypt为自定义域生成SSL证书。 gem非常简单易用。 安装/配置后,我可以生成证书,数据将存储在数据库中。 我想将certificate CRT和certificate KEY保存在相应的NGINX文件夹中: /etc/nginx/ssl/ 在那之后,我想: 复制文件/etc/nginx/sites-available/default并使用名称/etc/nginx/sites-available/customdomain.com保存 使用以下命令更改文件customdomain.com : 内容: server { listen 80; listen 443 ssl; server_name www.customdomain.com; ssl_certificate /etc/nginx/ssl/customdomain.crt; ssl_certificate_key /etc/nginx/ssl/customdomain.key; passenger_enabled on; root /home/ubuntu/myapp/current/public; gzip on; gzip_http_version 1.1; gzip_vary on; gzip_comp_level 6; gzip_proxied any; gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript gzip_disable “msie6”; location ^~ /assets/ { […]

NameError:未定义的局部变量或方法`remember_digest和NoMethodError

我的user.rb文件包含 class User < ActiveRecord::Base attr_accessor :remember_token before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } VALID_EMAIL_REGEX = /\A[\w+\-.]+@[az\d\-.]+\.[az]+\z/i validates :email, presence: true, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } has_secure_password validates :password, presence: true, length: { minimum: 6 } # […]

运行rails服务器(Rails 4)时找不到脚本/ rails?

当我尝试在调试模式下启动服务器时,我在RubyMine中收到此错误。 5:36:02 AM Error running Development: depot: Rails server launcher ‘/Users/eka/dev/tutorials/agile-rails-dev/depot/script/rails’ wasn’t found in project 我的Rubymine版本是5.0。

在para_to中使用rails params.merge

我想在link_to块中添加一个URL参数。 代码当前 ‘renderChart’, :class => “btn”, :remote => true, :params => params.merge(:limit => 5) %> 但这给了我一个错误。 它将:class和:action添加到url参数中,而不仅仅是:limit。 为什么? 编辑: 我从另一个看起来像这样的链接添加其他URL参数 link_to “Toggle Sort Direction”,:action => ‘renderChart’, :remote => true, :params => {:sort => “desc”} 因此,当用户单击其他链接时,我想将限制添加到url参数并保持排序参数

将局部变量传递给Rails 4中用于Ransack关联的部分层次结构

我正在尝试使用Ransack在我的所有模型的索引页面上实现搜索和排序表单。 我想尽可能干这样做,所以我在views / application文件夹中创建了三个部分: 视图/应用/ _table_search_and_sort_form.html.erb 视图/应用/ _condition_fields.html.erb 视图/应用/ _sort_fields.html.erb 每个代码如下: 视图/应用/ _table_search_and_sort_form.html.erb 视图/应用/ _condition_fields.html.erb <div class="field" data-object-name="”> 视图/应用/ _sort_fields.html.erb <div class="field" data-object-name="”> 在我的每个控制器中,我都有类似的东西: def index @search = Document.search(params[:q]) @documents = @search.result.paginate(:page => params[:page]) @search.build_condition if @search.conditions.empty? @search.build_sort if @search.sorts.empty? end 然后我通过添加以下内容将表单添加到每个index.html.erb: 其中:associations数组对于每个模型是不同的,这取决于我希望可以从条件表单访问的关联。 当我不尝试通过两个部分向下传递:associations数组时,只需将数组硬编码到_condition_fields.html.erb中,例如: 一切正常(对于那个模型,在这种情况下为Document)。 当我尝试通过将:associations数组从索引传递到_table_search_and_sort_form并将其传递到_conditional_form来将其扩展到多个模型时,我收到以下错误: undefined local variable or method `associations’ Extracted source (around […]

Rails – ruby​​ / 2.1.0 / minitest / parallel_each.rb:67:in”:类’Minitest :: Unit’的未定义方法’_run_suites’(NameError)

我克隆了这个存储库: https : //github.com/railstutorial/sample_app_rails_4 我按照说明在我的本地机器中设置项目: cd /tmp git clone https://github.com/railstutorial/sample_app_rails_4.git cd sample_app_rails_4 cp config/database.yml.example config/database.yml bundle install –without production bundle exec rake db:migrate bundle exec rake db:test:prepare bundle exec rspec spec/ 但是当我运行“bundle exec rspec spec”进行测试时,我得到了这个输出: No DRb server is running. Running in local process instead … /usr/lib/ruby/2.1.0/minitest/parallel_each.rb:67:in `’: undefined method `_run_suites’ for class `Minitest::Unit’ (NameError) […]

Elasticsearch过滤最大值文档

我试图从相同的名称记录中获取文档的最大值。 例如,我有3个用户,其中2个具有相同的名称但是不同的关注者数量,我想根据followers_count的最大值从2个相同的名称返回1个文档。 { id: 1, name: “John Greenwood”, follower_count: 100 } { id: 2, name: “John Greenwood”, follower_count: 200 } { id: 3, name: “John Underwood”, follower_count: 300 } 结果就是, { id: 2, name: “John Greenwood”, follower_count: 200 } { id: 3, name: “John Underwood”, follower_count: 300 } 从2个相同的名字,最大的追随者获胜,其他单个也将来。 我有如下映射, “users-development” : { “mappings” : […]

将语言环境添加到rails4中的Singular控制器

我有一个单一的控制器,我想添加区域设置。 看起来像 class AboutController < ApplicationController def home end def markdown_syntax end end 我的about.en.yml看起来像 en: about: home: discover_message: ‘Discover, Track and Compare Open Source’ join_now: ‘Join Now’ whats_new: “What’s New” popular_projects: ‘Most Popular Projects’ active_projects: ‘Most Active Projects’ 我正在获得翻译缺失错误,因为它无法从about.en.yml识别 错误信息: translation missing: en.about.home.discover_message

Mailcatcher错误:~~>错误:有东西正在使用端口1025.您是否已经在运行MailCatcher?

我已经安装了gem mailcatcher。 当我想运行mailcatcher时,我有以下错误消息: $ mailcatcher /Users/romenigld/.rvm/gems/ruby-2.2.3@global/extensions/x86_64-darwin-14/2.2.0-static/bigdecimal-1.2.7/bigdecimal.bundle: warning: already initialized constant BigDecimal::BASE /Users/romenigld/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of BASE was here /Users/romenigld/.rvm/gems/ruby-2.2.3@global/extensions/x86_64-darwin-14/2.2.0-static/bigdecimal-1.2.7/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_ALL /Users/romenigld/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of EXCEPTION_ALL was here /Users/romenigld/.rvm/gems/ruby-2.2.3@global/extensions/x86_64-darwin-14/2.2.0-static/bigdecimal-1.2.7/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_NaN /Users/romenigld/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:121: warning: previous definition of EXCEPTION_NaN was here /Users/romenigld/.rvm/gems/ruby-2.2.3@global/extensions/x86_64-darwin-14/2.2.0-static/bigdecimal-1.2.7/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_INFINITY /Users/romenigld/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:121: warning: […]

基于其中一个实例对两组实例进行排序 – 视图 – Ruby on Rails

RoR App有post和类别,主视图是一组类别/post。 它显示每个类别的post(最多3天)。 不显示空类别。 我想对索引视图进行排序,以便首先显示具有更多近期post的类别。 因此,当为类别创建新post时,该类别会上升到应用程序的第一个“行”。 在类别中,post也应该从较新到较旧。 因此,我需要实现两个级别的排序,具有最新post的类别首先和post按类别中的创建日期排序。 我真的被卡住了,你会怎么实现这个? 我的控制器: def index @categories = Category.includes(:posts).select{|c| c.posts.where([‘created_at > ?’, 3.days.ago]).count > 0} end 我的看法: # show category name ?’, 3.days.ago]).each do |post| %> # show post title and date 更新:显示到目前为止我尝试过的内容: 我试图首先根据post的creation_date对@categories进行排序(如所解释的,类别has_many:post)。 在我的控制器中: @categories = Category.includes(:posts).order(‘posts.created_at’).select{|c| c.posts.where([‘created_at > ?’, 3.days.ago]).count > 0} 然后在我看来,在post加载时对post进行排序: # show category name […]