Tag: ruby on rails 3.1

ruby on rails association newbie

这可能被视为rails 3关联错误的重新发布。 但它是我无法理解的东西。 但是好的……继续这个交易……我在这里问了一个与表模式有关的问题。 post是这个表模式结构中的错误 ,查询是: `CREATE TABLE “pages” ( “id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “title” varchar(255), “body” varchar(255), “author” varchar(255), “email” varchar(255), “reference” varchar(255), “created_at” datetime, “updated_at” datetime);` 我被建议我应该为作者创建单独的表,这就是我尝试和搞砸了。 任何人都可以告诉我协会应该如何与我的方案一起工作? 我真的需要很好地理解ROR协会。 编辑-1 这是我的页面迁移代码: class CreatePages true, :limit => 50 t.string :body, :limit =>255 t.string :email, :unique => true, :limit => 50 t.string […]

PostsController#中的ActiveRecord :: RecordNotFound显示单击链接

错误 ActiveRecord::RecordNotFound in PostsController#show Couldn’t find Post with id=morecommented Request Parameters: {“id”=>”morecommented”} 我在哪里做错了? postscontroller #show action def show @post = Post.find(params[:id]) … end morecommented.html.erb ‘/posts’, :action => ‘show’, :id => t.id %> 耙路线 post GET /posts/:id(.:format) {:action=>”show”, :controller=>”posts”} …. posts_morecommented /posts/morecommented(.:format) {:controller=>”posts”, :action=>”morecommented”} routes.rb中: resources :posts match “posts/:id/categ” => “posts#categ” match “posts/:id/tag_posts” => “posts#tag_posts” match […]

无法使用Gemfile运行/安装Gems

当我给bundle install或bundle exec时,我收到此错误 无法在Gemfile中列出的任何gem源中找到gem’metants_as_ferret-0.4.4.gem(> = 0)ruby’。 显然,Gemfile中的第一个gem是acts_as_ferret-0.4.4,source是 来源’http://rubygems.org’ 我尝试了其他来源,但仍然没有工作!

使用Bundler和Capistrano进行部署时出现问题

我正在使用Ruby on Rails 3.1.0和Capistrano gem。 正如Bundler官方文档中的“使用Capistrano自动部署”部分所述,我在deploy.rb文件的顶部添加了deploy.rb require ‘bundler/capistrano’ 。 现在,当我运行cap deploy:migrations命令(部署并运行挂起的迁移)时,我收到以下错误: … * executing “cd //releases/20111026132212 && bundle install –gemfile //releases/20111026132212/Gemfile –path //shared/bundle –deployment –quiet –without development test” servers: [“”] [] executing command ** [out :: ] Some gems seem to be missing from your vendor/cache directory. ** [out :: ] Could not find libv8-3.3.10.2 […]

如何查看字符串是否为数字?

我有字符串”08″ ,我想知道这个字符串是否是数字。 我怎么能在Rails 3.1中做到这一点?

Ruby on Rails:同一表单中的多个输入字段 – 更改ID /值

有一个页面,其中有相同的东西的多个输入字段,post。 现在,当用户输入问题时,假设3个字段,保存到数据库的唯一字段是最后一个。 然而,它应该保存所有三个并给它们每个自己的post_id。 也; 如果用户没有为其他字段输入任何内容,则它也不应保存在数据库中。 new_step_4_html.erb projects_controller.rb def new_step_4 @post = Post.new end 现在,它只是提交一个:content字段,显然是因为它们都共享相同的id /值。 不幸的是,Railscasts#197适用于嵌套表单,因此他所做的javascript和帮助程序都适用于嵌套。 我认为这很简单。 来自IRC的人提到我可以在视图文件中做某种“3次”代码或其他什么?

急于加载和使用’where’方法的麻烦

我正在运行Ruby on Rails 3.1。 我正在使用includes方法,我想了解为什么当我在一个渴望加载的集合上调用where方法时,它会重新加载关联的对象,而不是仅仅在eager加载的集合中找到该对象。 由于所有相关对象都已被急切加载,我希望where方法不会命中数据库来重新加载这些对象! 也就是说,我有以下几点: article_categories = article .categories .where(:user_id => @current_user.id) .includes(:comments) 如果我跑 # CASE 1: article_categories.each do |article_category| article_category.comments.map(&:title) end 急切加载按预期工作:避免了“N + 1查询问题”。 但是,上面的代码还返回没有 “ :user_id == @current_user.id ”的注释标题,但我根本不想检索那些。 所以,因为我认为通过使用热切加载我已经获得所有注释,我使用了另外的where(:user_id => @current_user.id)语句,如下面的代码所示: # CASE 2: article_categories.each do |article_category| article_category.comments.where(:user_id => @current_user.id).map(&:title) end 但是,在这种情况下,急切加载不能按预期工作: 不能避免“N + 1查询问题”…但注释有“ :user_id == @current_user.id ”! 我想用“ […]

失踪的gem可以

Bundler could not find compatible versions for gem “railties”: In Gemfile: rails (= 3.2.3) ruby depends on railties (= 3.2.3) ruby jquery-rails (= 2.0.0) ruby depends on railties (3.2.5) 尝试“捆绑安装”时我收到了错误消息,这是我的gemfile source ‘https://rubygems.org’ gem ‘rails’, ‘3.2.3’ # Bundle edge Rails instead: # gem ‘rails’, :git => ‘git://github.com/rails/rails.git’ group :development do gem ‘sqlite3’, ‘1.3.5’ end gem ‘json’ […]

没有刷新页面如何显示闪存错误?

我有一个提交表单,显示在灯箱中。 我非常认真地validation了表单,但是有些情况下已经提交了播放列表,在这种情况下,在提交表单之前我无法分辨。 目前我有:disable_with => ‘Submitting…’ 如果错误被发送回表单,并且提交按钮将重新启用,那将是非常棒的。 这可能没有太多的复杂性吗? 我还有第二个相关的问题…因为我的表单在灯箱中,它的代码实际上是在索引页面上(我的应用程序只是一页)。 这意味着我的索引操作中没有’new’动作,而是@playlist = Playlist.new(:title => …) (以及@playlists = Playlist.all等)。 在我的路线中,我这样做: resources :playlists, :only => [:create] 这听起来跟我做的一样吗? 编辑:HEre是一些代码,虽然它基本上就像你想象的那么简单。 以下类型的作品……如果有效,则创建播放列表,否则无效。 两次调用create.js.erb ..我现在不知道如何使这项工作完成。 在成功我需要关闭窗口,失败时我需要将错误加载到已经在屏幕上的forms。 我不知道那是怎么回事:/ before_filter :load_genres, :only =>[:index, :user] before_filter :new_playlist, :only => [:index, :new] def index @playlists = Playlist.order(‘created_at DESC’).page(params[:page]).per(30) end def create @playlist = Playlist.new(params[:playlist]) respond_to do |format| […]

运行rails服务器时,Windows上没有Javascript运行时

我是Ruby on Rails的新手,我在Windows PC上设置它时遇到了麻烦。 我已成功按照http://rubyonrails.org/download上的说明操作。 但是,当我去运行rails server命令时,我想出了这个输出: C:/Ruby192/lib/ruby/gems/1.9.1/gems/execjs-1.2.9/lib/execjs/runtimes.rb:47:in `a utodetect’: Could not find a JavaScript runtime. See https://github.com/sstephen son/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) from C:/Ruby192/lib/ruby/gems/1.9.1/gems/execjs-1.2.9/lib/execjs.rb:5:in `’ from C:/Ruby192/lib/ruby/gems/1.9.1/gems/execjs-1.2.9/lib/execjs.rb:4:in `’ from C:/Ruby192/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_ script.rb:1:in `require’ from C:/Ruby192/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_ script.rb:1:in `’ from C:/Ruby192/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee- script.rb:1:in `require’ from C:/Ruby192/lib/ruby/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee- script.rb:1:in `’ from C:/Ruby192/lib/ruby/gems/1.9.1/gems/coffee-rails-3.1.1/lib/coffee-r ails.rb:1:in `require’ from C:/Ruby192/lib/ruby/gems/1.9.1/gems/coffee-rails-3.1.1/lib/coffee-r ails.rb:1:in […]