ruby-on-rails-3

Ruby on Rails 3 Release date [closed]

你。 提交于 2019-12-24 06:35:09
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . Is there a release date for Ruby on Rails 3? I've been searching but nothing yet. 回答1: read this http://www.ruby-forum.com/topic/213412#new 回答2: Rails 3

Query Activerecord HABTM relationship to include ALL elements of an array

时光毁灭记忆、已成空白 提交于 2019-12-24 06:25:12
问题 I have a Forum and ForumTag HABTM relationship. I also have an array of variables named @tags . This array contains the names of some ForumTags. I want to be able to query and find all forums that have ALL the values of the array. I currently have: @forums = Forum.joines(:forum_tags).where(:forum_tags => {:name => @tags}).includes(:forum_tags).all However, this returns all the forums that have AT LEAST ONE value in the array. 回答1: The following will require the forums to have all the forum

Rails: build for difference between relationships

狂风中的少年 提交于 2019-12-24 06:07:53
问题 A doc has many articles and can have many edits . I want to build an edit for each article up to the total number of @doc.articles . This code works with the first build (i.e., when no edits yet exist). def editing @doc = Doc.find(params[:id]) unbuilt = @doc.articles - @doc.edits unbuilt.reverse.each do |article| @doc.edits.build(:body => article.body, :article_id => article.id, :doc_id => @doc.id) end end But when edits already exist it'll keep those edits and still build for the @doc

Is it possible to use question marks in 'order' methods-clauses?

 ̄綄美尐妖づ 提交于 2019-12-24 06:01:30
问题 I am using Ruby on Rails 3.2 and I would like to know if there is a way to make the following: @categories.order('user_id = ? DESC', params[:id]) @categories.order('user_id = ? DESC', @user.id) # Note: It is almost the same as `@categories.where('user_id = ?', params[:id])` # but for the `order` clause. Above statements generates this error: ActiveRecord::StatementInvalid (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for

What is the difference between ModelName.all and ModelName.where('')

房东的猫 提交于 2019-12-24 05:57:13
问题 I have the following relations: User --has many--> Reminders --has many--> Payments I get all the payments of a user as payments = User.reminders.collect{|reminder| reminder.payments.between(from_date, to_date)}.flatten and then data = payments.select("SUM(amount) as total_payment, MONTH(payment_date) as month, YEAR(payment_date) as year").group("MONTH(payment_date), YEAR(payment_date)").map{|payment| [payment.total_payment, "#{payment.month}/#{payment.year}"]} I was trying to run the above

What is the difference between ModelName.all and ModelName.where('')

我与影子孤独终老i 提交于 2019-12-24 05:57:03
问题 I have the following relations: User --has many--> Reminders --has many--> Payments I get all the payments of a user as payments = User.reminders.collect{|reminder| reminder.payments.between(from_date, to_date)}.flatten and then data = payments.select("SUM(amount) as total_payment, MONTH(payment_date) as month, YEAR(payment_date) as year").group("MONTH(payment_date), YEAR(payment_date)").map{|payment| [payment.total_payment, "#{payment.month}/#{payment.year}"]} I was trying to run the above

How to test a nested form with RSpec and FactoryGirl?

萝らか妹 提交于 2019-12-24 05:38:09
问题 In my Rails project I have a User that can have many Projects which in turn can have many Invoices . Each Invoice can have many nested Items . class Invoice < ActiveRecord::Base attr_accessible :number, :date, :recipient, :project_id, :items_attributes belongs_to :project belongs_to :user has_many :items, :dependent => :destroy accepts_nested_attributes_for :items, :reject_if => :all_blank, :allow_destroy => true validates :project_id, :presence => true def build_item(user) items.build(:price

How to keep file field value when validation failed

醉酒当歌 提交于 2019-12-24 04:49:26
问题 I have a classic rails 3 form with a file field, everything works fine, upload works and data is saved to database. When a validation failed, for example, title is missing, then the user is sent back to the form with a render :action => new . Normal. But the problem here, is that the user have to select another time its file. Any way to avoid that? 回答1: Typically you don't want to process files until after validations have run or you're going to repeatedly store files that possibly don't have

How do you make each option in a drop down menu a link with the association simple_form call?

假装没事ソ 提交于 2019-12-24 04:23:27
问题 I have this form using the simple_form plugin: <%= simple_form_for([@video, @video.comments.new], :remote => true) do |f| %> <%= f.association :comment_title, :collection => @video.comment_titles, :label => "Comment Title:", :include_blank => false %> <%= f.input :body, :label => false, :placeholder => "Post a comment." %> <%= f.button :submit, :value => "Post" %> <% end %> and this creates a drop down list with this line: <%= f.association :comment_title, :collection => @video.comment_titles

rails console error require './example_user'

大兔子大兔子 提交于 2019-12-24 04:18:40
问题 I'm using the railstutorial at http://ruby.railstutorial.org/chapters/rails-flavored-ruby#sec:a_user_class I've been told to type require './example_user' but... I get this error LoadError: cannot load such file -- example_user from /Users/snook3/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require' and then further and further errors I imagine that I'm not linking correctly to that folder, can anyone let me know where I should be linking too?