当我使用它attr_accessible来指定我的模型I中的哪些字段将公开时,脚本/控制台也是如此?我的意思是我没有指定的东西attr_accessible也不能通过控制台访问?
我正在尝试使用jQuery,一切都很棒,直到现在,当我尝试渲染部分并将其附加到div时.以下是我设置的方法:
我有一个响应js的动作:
def index
@objects = Object.find(:all)
respond_to do |format|
format.js
end
end
Run Code Online (Sandbox Code Playgroud)
还有一个名为index.js.erb的模板,里面有一些javascript:
alert("hello world");
Run Code Online (Sandbox Code Playgroud)
Firebug返回"text/javascript"响应,其中包含:
alert("hello world");
Run Code Online (Sandbox Code Playgroud)
但是没有出现警报窗口,也没有任何其他JavaScript工作.我检查了http://railscasts.com/episodes/136-jquery 并且或多或少跟随.我尝试了其他一些东西,比如使用.rjs而不是.erb并将它放在我的模板中:
page.alert("hello world");
Run Code Online (Sandbox Code Playgroud)
但我得到了相同的结果,浏览器从不执行JS.
任何人都知道为什么JavaScript没有被执行?
我正在运行Rails 2.3.4.
我把searchlogic放在我的gemfile中...现在我的rails服务器将无法启动:(
这是错误消息
gems/ruby-1.8.7-p299/gems/activesupport-3.0.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method': undefined method `merge_joins' for class `Class' (NameError)
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/activesupport-3.0.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/searchlogic-2.4.27/lib/searchlogic/active_record/consistency.rb:8:in `included'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/searchlogic-2.4.27/lib/searchlogic/active_record/consistency.rb:7:in `class_eval'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/searchlogic-2.4.27/lib/searchlogic/active_record/consistency.rb:7:in `included'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/searchlogic-2.4.27/lib/searchlogic.rb:34:in `include'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/searchlogic-2.4.27/lib/searchlogic.rb:34
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in `require'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in `require'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/bundler-1.0.0/lib/bundler/runtime.rb:62:in `each'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/bundler-1.0.0/lib/bundler/runtime.rb:62:in `require'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/bundler-1.0.0/lib/bundler/runtime.rb:51:in `each'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/bundler-1.0.0/lib/bundler/runtime.rb:51:in `require'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/bundler-1.0.0/lib/bundler.rb:112:in `require'
from /Users/omiohoro/glowing-rain-75/config/application.rb:7
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/railties-3.0.0/lib/rails/commands.rb:28:in `require'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/railties-3.0.0/lib/rails/commands.rb:28
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/railties-3.0.0/lib/rails/commands.rb:27:in `tap'
from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/railties-3.0.0/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
Run Code Online (Sandbox Code Playgroud)
我该如何解决?在此先感谢欢呼tabaluga
我是Ruby on Rails的新手.在Rails应用程序中,我看到了一些如下代码:
在模型中,有一个类Car:
class Car < ActiveRecord::Base
...
end
Run Code Online (Sandbox Code Playgroud)
在控制器中,有一个方法" some_method "
class CarsController < ApplicationController
def some_method
@my_car = Car.new()
#What does the following code do?
#What does "<<" mean here?
@my_car.components << Component.new()
end
end
Run Code Online (Sandbox Code Playgroud)
我有三个问题要问:
1.在控制器的代码中@my_car.components << Component.new(),它做了什么?什么<<意思?
2.在Ruby-On-Rails或Ruby中是否还有其他"<<"用法?
3.如果使用" << " ,类是否Car必须显式定义has_many与Component类的关联或者是否可以使用" << "添加新关联,即使关联未在类中明确定义?CarCar
我有一个范围来查询今天的电话.基于范围,我用它来计算今天的通话量.
我的日期以UTC格式存储,但rails会转换为我当地的时区.我想要做的是在今天00:00到23:59之间找到所有电话.
范围:
scope :today, where("DATE(transfer_date) BETWEEN ? AND ?", Time.zone.now.utc.beginning_of_day, Time.zone.now.utc.end_of_day)
Run Code Online (Sandbox Code Playgroud)
irb输出:(因UTC而捕获的呼叫)
irb(main):010:0> Call.last.transfer_date
Call Load (0.9ms) SELECT "calls".* FROM "calls" ORDER BY "calls"."id" DESC LIMIT 1
=> Sun, 07 Oct 2012 19:45:00 CDT -05:00
irb(main):011:0>
irb(main):011:0> Call.last.transfer_date.utc
Call Load (1.3ms) SELECT "calls".* FROM "calls" ORDER BY "calls"."id" DESC LIMIT 1
=> 2012-10-08 00:45:00 UTC
Run Code Online (Sandbox Code Playgroud)
我正在试图弄清楚如何只查询今天00:00到23:59之间的通话.到目前为止尝试使用和不使用utc,zone等的范围都不起作用.它一直根据UTC提取范围,包括昨天的呼叫(昨天如果用当地时区格式化).
如何在两次之间查询以获得正确的输出?我有点迷失在这里.
我正在为Redmine开发一个插件.如何为其创建迁移?
如果我使用script/generate plugin_migration,它将被放在/ db/migrate文件夹中,但我需要它在我的插件的文件夹中.
我一直在试图找出在rails应用程序中处理传入电子邮件的最佳方法.我意识到"最佳实践"是非常主观的,所以我首先要说明我的主要关注点是可扩展性和效率.这是一个问题,主要是因为我的使用将涉及处理潜在的大附件.
似乎就在昨天,接受的方法是使用ActionMailer接收电子邮件,但最近我偶然发现了几篇文章说这是低效的,因为它产生了每个电子邮件的新的rails实例(大量可怕).
最近,这篇文章引起了我的注意:http: //jasonseifer.com/2009/04/24/receving-email-with-rails
该文章谈到了ActionMailer系统的精简版本,该系统并未被强制生成整个rails实例,但是这些评论还谈到了其他几个选项,如专用邮件目录(maildir?)和imap/pop检索.
我的问题是:有没有人对在rails应用程序(包括附件)中处理传入电子邮件的最佳选项有什么想法?
快速背景:我有一个字符串,其中包含对其他页面的引用.页面链接使用格式:"#12".哈希后跟页面的ID.
说我有以下字符串:
str = 'This string links to the pages #12 and #125'
Run Code Online (Sandbox Code Playgroud)
我已经知道需要链接的页面的ID:
page_ids = str.scan(/#(\d*)/).flatten
=> [12, 125]
Run Code Online (Sandbox Code Playgroud)
如何遍历页面ID并将#12和#125链接到各自的页面?我遇到的问题是如果我执行以下操作(在rails中):
page_ids.each do |id|
str = str.gsub(/##{id}/, link_to("##{id}", page_path(id))
end
Run Code Online (Sandbox Code Playgroud)
这适用于#12,但它将#125的"12"部分链接到ID为12的页面.
任何帮助都是极好的.
我熟悉像Deadweight这样的工具,用于查找未在Rails应用程序中使用的CSS,但是对于图像有什么存在吗?我正坐在一个拥有大量资产目录的项目中,与各种设计师合作,我正在努力减少这个项目的成本.将资产转移到我们的CDN时尤其痛苦.
有什么想法吗?
我正在尝试配置rails应用程序以远程连接到postgres数据库.我注意到mysql的连接适配器有选项,指定设置ssl连接所需的信息,但postgres/pg适配器没有等效的选项.
谷歌搜索后,我也找不到任何东西(只通过ssh隧道连接).
所以简单地说,是试图让rails postgres适配器通过ssl连接死路?
谢谢.任何帮助或方向表示赞赏.
-H
ruby-on-rails ×10
ruby ×6
activerecord ×3
actionmailer ×1
assets ×1
email ×1
erb ×1
gsub ×1
image ×1
javascript ×1
jquery ×1
migration ×1
plugins ×1
postgresql ×1
redmine ×1
regex ×1
searchlogic ×1
timezone ×1