小编pja*_*mer的帖子

嵌套属性和通过控制器添加属性?

由于这个问题很难描述,这是我能提出的最佳标题,所以这里有一些代码.

鉴于三个模型Parent,Child && Grandchild.

Parent <  ActiveRecord::Base
  has_many :children
  has_many :grandchildren
  accepts_nested_attributes_for :child
end

Child <  ActiveRecord::Base
  belongs_to :parent
  has_many :kids, :as => :grandchildren #this is just an example
  accepts_nested_attributes_for :grandchild
end

Grandchild <  ActiveRecord::Base
  belongs_to :parent
  belongs_to :child
end
Run Code Online (Sandbox Code Playgroud)

我想将current_user.id添加到在Parent#new期间创建的子记录和Grandchild记录中.我现在使用隐藏字段,因为我找不到添加它们的好方法.

也许有人可以通过创建回调来在创建时添加current_user.id来提供帮助?无论如何,我从来没有太多运气进入模型,但你很聪明.

思考?

ruby-on-rails nested-attributes

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

使用Active Record对相关表进行求和

如何将一个关联中的所有"总"列相加?

我的SQL-fu糟透了,所以我想学习如何使用Active Record for my rails 2.3.5应用程序(所以没有花哨的语法,只是请;-)而且我在MySQL上.

比方说我有:


Shop 

has_many :customers
has_many :transactions, :through => :customers

Run Code Online (Sandbox Code Playgroud)

很正常的东西.


shop = Shop.first
shop.transactions
=> 100 

Run Code Online (Sandbox Code Playgroud)

好的,问题的所有背景:

我想total在过去一年(2010年1月1日,2010年12月31日)的交易中对该列进行总结,并按客户显示.

虽然我知道如何对事务进行分组并找到条件,但这是我缺少SQL让我失望的总和部分.


first = Date.new(2010, 01, 01)
last = Date.new(2010, 12, 31)

shop.transactions(:conditions => {:created_at => first..last}, :group => :customer_id, :include => sum(:total))

Run Code Online (Sandbox Code Playgroud)

我只是刺了一下,我是在正确的轨道上吗?

activerecord ruby-on-rails

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

Rails 3 bundler&rvm:捆绑的宝石不会出现在gem列表中?

ubuntu 10.04黏糊糊的lynx或其他所谓的生产应用程序的操作系统.我也安装了rvm,然后在mac上,开发和生产红宝石和宝石都是一样的.

现在,我习惯于看到所有捆绑的宝石gem list......正常情况下,但是当我gem list在制作中时,我没有看到任何捆绑的宝石.

这意味着我不能使用rails c或任何其他宝石.

我发现我可以做什么bundle exec rails c或者其他什么并且以这种方式使用控制台,但是我更感兴趣的是为什么会发生这种情况,以及如何修复它以便宝石列表拥有所有的宝石.它感觉很对.

思考?

ruby-on-rails bundler rvm

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

ido-mode和TAB键在24.0.x0版本中无法正常工作

[Tab] - display possible completion in a buffer (or open the file or go down the directory if there is only one possible completion).
Run Code Online (Sandbox Code Playgroud)

这篇文章来自于ido模式emacs wiki.

在我的emacs 24.0.50每晚从5月5日开始构建,在OSX上我的功能是当按TAB时它用于循环我的选择.现在,如果我点击tab,并且有多个匹配的文件,它会选择一个缓冲区.

这很烦人,基本上,我希望我的旧标签完整(ala bash)样式.

有人知道怎么修这个东西吗?我可以映射Tab键,但是要做什么?

emacs

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

尝试启动rails服务器时出现语法错误

我最近开始研究一个我从github克隆的项目.

每次我尝试启动rails服务器时都会出现以下错误:

 
/Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in load': /Users/thomas/Projects/BillingMiddleware/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end (SyntaxError)
...sion_store :cookie_store, key: '_BillingMiddleware_session'
                              ^
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:inload'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in load_dependency'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:inload'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:588
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:587:in each'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:587
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:30:ininstance_exec'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:30:in run'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:55:inrun_initializers'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:54:in each'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:54:inrun_initializers'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/application.rb:136:in initialize!'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:insend'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in method_missing'
    from /Users/thomas/Projects/BillingMiddleware/config/environment.rb:5
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:inrequire'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:inload_dependency'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require'
    from /Users/thomas/Projects/BillingMiddleware/config.ru:4
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:ininstance_eval'
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in initialize'
    from …
Run Code Online (Sandbox Code Playgroud)

ruby syntax gem ruby-on-rails rvm

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

使用CSS仅将div高度设置为浏览器的高度

*我使用CSS制作布局.

而我正在尝试做的是让headerdiv占用一定数量的高度像素,比如100px,然后contentdiv占据浏览器窗口高度的其余部分.

即浏览器窗口高度减去标题div的高度.

所以HTML如下,

<div id="header"></div>

<div id="content"></div>
Run Code Online (Sandbox Code Playgroud)

....这是我到目前为止所拥有的CSS.

html, body {margin: 0; padding: 0; height: 100%;}

#header {width: 100%; height: 100px; background-color: #333;}

#content {position: relative; top: 10px; width: 100%; /*height: auto !important;*/  min-height: 100%; background-color: #999; }
Run Code Online (Sandbox Code Playgroud)

我知道,因为我已经做到这一点,这可以用JS/Jquery根据浏览器的高度设置内容div的高度,但我很想知道是否有一种方法可以使用CSS .

正如您从下面的小提琴中看到的那样,当前的CSS只会使内容div从屏幕底部开始拍摄.

http://jsfiddle.net/PysLY/

html css height

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

Multiple无法从客户端接收数据:通过对等Postgresql和Resque重置连接

我有一个运行Postgresql的服务器.在日志中我看到这个消息为我的resque基于'工人'框,每分钟多次.几分钟没有消息,其他可能是10次.

2016-01-12 13:40:36 EST:1.1.8.2(33899):[16141]: LOG:  could not receive data from client: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)

现在,当我进入1.1.8.2框中观察netstat -ntp我没有看到端口33899,并且其中大部分至少在40xxx范围内.这可能是猜想,但我不知道为什么Redis/Resque/Puma Rails堆栈会打印出这些消息,更不用说这意味着即使我到底了.

如果它们"正常"关闭,我会获回记忆吗?

这是一件值得警惕的事吗?

当数据库框和工作框都不再显示端口时,如何调试打开的OLD端口?

postgresql resque puma

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