小编Ser*_*sev的帖子

为什么Rails一直告诉我未经许可的参数,即使我允许它?

我有一个Profile模型,具有以下内容:

  has_many :transcripts, dependent: :destroy
  accepts_nested_attributes_for :transcripts, allow_destroy: true
Run Code Online (Sandbox Code Playgroud)

在我的Transcript模型上,我有以下内容:

include TranscriptUploader[:attachment]
Run Code Online (Sandbox Code Playgroud)

这是一个Shrine Uploader mount.

在我app/views/profile/_form.html.erb,我有以下内容:

    <div id="transcripts" class="text-center">
      <% if @profile.transcripts.any? %>
        <% @profile.transcripts.each do |transcript| %>
          <%= link_to "Click to view Transcript", transcript.url %>
        <% end %>
      <% end %>

      <%= f.simple_fields_for :transcripts do |transcript| %>
        <%= render 'transcript_fields', f: transcript %>
      <% end %>
      <br />
      <div class="links">
        <%= link_to_add_association 'Add Transcript', f, :transcripts, class: "btn btn-success add-transcript-button" %>
      </div>
    </div> …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails strong-parameters ruby-on-rails-5

2
推荐指数
1
解决办法
1629
查看次数

将正整数转换为负整数

我是编程新手,很想知道为什么以下返回负整数:

-num.abs
Run Code Online (Sandbox Code Playgroud)

我的理解是 abs 将值作为正数返回,但这会将任何正数返回为负数?

ruby

2
推荐指数
1
解决办法
39
查看次数

从mongodb shell运行具有mongodb查询的脚本

我的mongodb数据库文档中有几个ID.我需要通过脚本在这些ID上创建索引,这样我就不必一次又一次地运行ensureIndex命令.

db.getCollection("elements").ensureIndex({customerId:1});
db.getCollection("elements").ensureIndex({userId:1});
........
Run Code Online (Sandbox Code Playgroud)

我只是运行脚本(包含所有这些命令),我应该完成.知道如何从mongodb shell运行脚本吗?那个脚本的扩展应该是什么?

朱希.

mongodb

1
推荐指数
2
解决办法
1万
查看次数

Ruby - 无法加载捆绑器

我用rvm gem install bundler安装了bundler.这里有什么问题?

还用这些选项重新安装 -

apt-get install libncurses5-dev libreadline5-dev libreadline-dev librequire-dev
rvm use ruby-1.9.3-p125 --default
rvm reinstall librequire-dev libbundler-dev --with-readline-dir=/usr/include/readline



       $ rails new proj

           exist
       identical  README.rdoc
       identical  Rakefile
       identical  config.ru
       identical  .gitignore
       identical  Gemfile
           exist  app
       identical  app/assets/images/rails.png
       identical  app/assets/javascripts/application.js
       identical  app/assets/stylesheets/application.css
       identical  app/controllers/application_controller.rb
       identical  app/helpers/application_helper.rb
           exist  app/mailers
           exist  app/models
       identical  app/views/layouts/application.html.erb
       identical  app/mailers/.gitkeep
       identical  app/models/.gitkeep
           exist  config
       identical  config/routes.rb
       identical  config/application.rb
       identical  config/environment.rb
           exist  config/environments
       identical  config/environments/development.rb
       identical  config/environments/production.rb
       identical  config/environments/test.rb
           exist  config/initializers
       identical  config/initializers/backtrace_silencers.rb
       identical  config/initializers/inflections.rb …
Run Code Online (Sandbox Code Playgroud)

ruby bundler

1
推荐指数
1
解决办法
5645
查看次数

Javascript参数

我输入卷轴(0,10,200,10); 但是当它运行时,它传递字符串"xxpos"或"yypos",我确实尝试了它没有appostraphes,但它只是没有工作.

scroll = function(xpos,ypos,time,rounds){
    var xxpos = xpos*1;
    var yypos = ypos*1;
    var rrounds = rounds*1;
    var ttime = time*1;
    x = 0;
    xyz=window.setInterval("scroller('xxpos','yypos','ttime','rrounds')",ttime);
}
function scroller(xpos,ypos,time,rounds){
    alert(xpos + ypos + time + rounds);
}
Run Code Online (Sandbox Code Playgroud)

javascript

1
推荐指数
1
解决办法
86
查看次数

比较数组中的内容

如何在ruby中比较数组中的值?

我想比较数组中的值来检查数组的最大值.

ruby arrays

1
推荐指数
1
解决办法
99
查看次数

redis是如何实现进程间通信的?

我们可以简单地使用redis来实现远程通信,例如:

redis.StrictRedis(host=REDIS_IP,port=PORT)
Run Code Online (Sandbox Code Playgroud)

我不知道redis是否以相同的模式实现了远程和本地?

也许我只是想知道redis如何以不同的方式实现网络通信和进程间通信?

如果有问题,请指出.谢谢

redis

1
推荐指数
1
解决办法
2442
查看次数

数组的attr_writer

我对Ruby的attr_writer感到困惑.我正在尝试在数组中添加一个值,但我遇到以下错误:

第13行:#(NoMethodError)的未定义方法`test'

class Pet
  attr_writer :test
  def initialize()
    @test = []
  end
end

pet = Pet.new()
pet.test << "Test was a pet"
Run Code Online (Sandbox Code Playgroud)

为什么?据我了解,attr_writer相当于一个setter方法.请解释.谢谢.

ruby

1
推荐指数
1
解决办法
542
查看次数

如果尚未设置 cookie,则设置 cookie

我该如何用 ruby​​ 写这样的东西

 if( !cookies['isActive']){
    cookies['isActive'] = true
  } 
Run Code Online (Sandbox Code Playgroud)

我正在考虑将其放入应用程序控制器中。或者也许有更好的方法。

如果尚未设置,我基本上想设置一个 cookie。它应该只在浏览器打开时存在。

然后在应用程序视图方面,我希望能够查看该 cookie 是否已设置,如果没有设置,那么我希望能够运行一些脚本。

ruby ruby-on-rails ruby-on-rails-3

1
推荐指数
1
解决办法
629
查看次数

Ruby 中如何解释嵌套数组的声明?

当我处理数组时,我在 Ruby 中的嵌套数组声明中错过了一个逗号,但语言以其他方式解释了它。如果有人熟悉这种行为,请考虑一下。

arr = [1,2[1,8]]
[1, 1] 
arr = [1,5[6,4]]
[1, 0] 
arr = [1,3[1,6]]
[1, 1] 
arr = [1,6[1,6]]
[1, 3] 
arr = [1,7[1,6]]
[1, 3] 
arr = [1,0[1,6]]
[1, 0] 
arr = [1,8[1,6]]
[1, 4]
Run Code Online (Sandbox Code Playgroud)

应根据虚假声明提出例外情况

ruby

1
推荐指数
1
解决办法
66
查看次数