在我们的rails rfq.js.coffee中,我们只有一个简单的js代码:
$(function() {
$('#need_report').change(function(){
if ($(this).val() == true) {
$('#report_language').hide();
} // end if
}); // end change()
}); // end ready(function)
Run Code Online (Sandbox Code Playgroud)
但是,此代码会导致错误,指出第一行中的function()是保留字.由于第一行基本上是一个jquery $(document).ready(function () {}),我们不知道为什么会出现这个错误.有什么想法吗?非常感谢.
<%= params[:action] %>
Run Code Online (Sandbox Code Playgroud)
和
<%= params['action'] %>
Run Code Online (Sandbox Code Playgroud)
显示
index
Run Code Online (Sandbox Code Playgroud)
但这种语法有什么区别?
有没有办法在rails 3.0中生成一个脚手架,以便不创建scaffold.css?我可以输入命令行中的某些内容跳过该步骤?
谢谢
在rails 3.1中使用资产管道时,它会创建一个默认值application.js:
//= require jquery
//= require jquery_ujs
//= require_tree .
Run Code Online (Sandbox Code Playgroud)
但我什么时候需要包括我的所有JavaScript?在大多数情况下,我们为不同的控制器/视图使用不同的javascrips?
我正在创建一个新项目:
rails new ggg --database=mysql
Run Code Online (Sandbox Code Playgroud)
并得到以下输出:
create
create README
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/images/rails.png
create app/assets/javascripts/application.js
create app/assets/stylesheets/application.css
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/mailers
create app/models
create app/views/layouts/application.html.erb
create app/mailers/.gitkeep
create app/models/.gitkeep
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/initializers/wrap_parameters.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create …Run Code Online (Sandbox Code Playgroud) 我一直在搜索stackoverflow近2个小时,现在经历类似的问题,但答案似乎不起作用.
我有以下代码:
<%= select_tag "name_dropdown", options_from_collection_for_select(@models, "friendly_id", "name") %>
Run Code Online (Sandbox Code Playgroud)
我想显示我之前选择的选项,而不是默认情况下转到第一个标签.
在其他问题中,他们建议添加以下内容(它们都不起作用).
<%= select_tag "name_dropdown", options_from_collection_for_select(@models, "friendly_id", "name", "1") %>
Run Code Online (Sandbox Code Playgroud)
要么:
<%= select_tag "name_dropdown", options_from_collection_for_select(@models, "friendly_id", "name", @models.first.id) %>
Run Code Online (Sandbox Code Playgroud)
PS.我正在使用Rails 3.1.RC4
我有一个像控制器一样的动作
def index
@videos = Video.all.to_a
respond_to do |format|
format.xml { render :xml => @videos }
format.json { render :json => @videos }
end
end
Run Code Online (Sandbox Code Playgroud)
视频有属性name和title.
我希望返回的xml只包含title.
如何从响应中限制它.
我安装了一切.但是当我运行"rake db:create"时,我得到以下内容:
Ken-Vogts-MacBook:sixmonths ken$ rake db:create
(in /Users/ken/sixmonths)
rake aborted!
no such file to load -- pg
Run Code Online (Sandbox Code Playgroud)
这是我的database.yml:
development:
adapter: postgresql
encoding: unicode
database: sixmonths_development
pool: 5
username: postgres
password: xxxxxxxx
test:
adapter: postgresql
encoding: unicode
database: sixmonths_test
pool: 5
username: sixmonths
password: xxxxxxxx
production:
adapter: postgresql
encoding: unicode
database: sixmonths_production
pool: 5
username: sixmonths
password: xxxxxxxx
Run Code Online (Sandbox Code Playgroud)
我可以在运行时看到pg已安装:gem list
我尝试在stackoverflow上的另一篇文章中用"pg"替换"postgresql",但结果如下:
Ken-Vogts-MacBook:sixmonths ken$ rake db:create
(in /Users/ken/sixmonths)
Run Code Online (Sandbox Code Playgroud)
看起来很酷,对吗?
不.接下来,我尝试"rake db:schema:dump",我得到了这个:
Ken-Vogts-MacBook:sixmonths ken$ rake db:schema:dump
(in /Users/ken/sixmonths)
rake aborted!
Please install the …Run Code Online (Sandbox Code Playgroud) 我正在使用https://github.com/sferik/rails_admin来处理我的管理界面.
可以根据此模型中存在的当前列(id,created_at等)过滤模型.
我希望能够为关联添加自定义过滤器.
例如:
当我在探索"城镇"模型时,我希望能够只显示有一个或多个项目的城镇.
我可以通过向城镇添加一个新列来实现这一点,将has_projects称为布尔值,当有一个或多个项目关联时,它将设置为true,但我觉得必须有一种更清晰的方法来制作自己的自定义过滤器?
我rvm use 1.9.2在尝试运行时使用然后rails s我收到以下错误.
/Users/pel/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0.rc5/lib/action_view/railtie.rb:34:in `block (3 levels) in <class:Railtie>': undefined method `debug_rjs=' for ActionView::Base:Class (NoMethodError)
Run Code Online (Sandbox Code Playgroud) ruby ×3
bundle ×1
coffeescript ×1
controller ×1
filter ×1
gem ×1
javascript ×1
jquery ×1
postgresql ×1
rails-admin ×1
scaffold ×1