ruby-on-rails-3

Rails query interface where clause issue?

六眼飞鱼酱① 提交于 2020-01-24 01:08:12
问题 i am try to run the sql query as follows @applicants = Applicant.where("applicants.first_name LIKE ? AND applicants.status = ?", "%#{people}%", ["new", "in-review"] ) I am getting an mysql error as : ActionView::Template::Error (Mysql2::Error: Operand should contain 1 column(s): SELECT `applicants`.* FROM `applicants` WHERE (applicants.first_name LIKE '%sh%' AND applicants.status = 'new','in-review')): can anyone help me in this thanks in advance 回答1: You have to use IN clause of mysql

Validate date and time fields together in rails model

此生再无相见时 提交于 2020-01-23 23:21:50
问题 EDIT: In case the question below looks a bit 'extensive', the summary is that I just want to combine a date field and an optional time field in my model purely for the purpose of validating it using a date validator but I can't get my test to fail correctly when I pass in a string as the time. EDIT 2: Since I'm still struggling to find a way to join a date object with a time object for the purpose of validation then I wondered if I could just validate that the time value was a Time object

Validate date and time fields together in rails model

旧城冷巷雨未停 提交于 2020-01-23 23:21:13
问题 EDIT: In case the question below looks a bit 'extensive', the summary is that I just want to combine a date field and an optional time field in my model purely for the purpose of validating it using a date validator but I can't get my test to fail correctly when I pass in a string as the time. EDIT 2: Since I'm still struggling to find a way to join a date object with a time object for the purpose of validation then I wondered if I could just validate that the time value was a Time object

Processing orders after minimum order met - Rails 3

与世无争的帅哥 提交于 2020-01-23 21:56:07
问题 My app has deals where orders are made once a minimum order amount is met. Currently I have setup orders that that orders are placed right after the order is submitted which is all working. Now I need to change the process so that orders are processed once the minimum order number for the deal is met. Should I use delayed_job for this or maybe a cron process? Here is the process I was thinking of following. Delaying Orders Until Orders minimum is met Find deals that are still active Then find

How to retrieve a class name?

本小妞迷上赌 提交于 2020-01-23 16:41:04
问题 I am using Ruby on Rails 3.0.7 and I would like to retrieve the class name, also if it is namespaced. For example, if I have a class named User::Profile::Manager I would retrieve the Manager string from that using some unknown to me Ruby or Ruby on Rails method and in a secure way. BTW : What other "usefull" information that are "commonly" used can I get for the class? 回答1: Some useful simple metaprogramming calls: user = User::Profile::Manager.new(some_params) user.class # => User::Profile:

How to get devise to work with accepts_nested_attributes_for in a has one relationship?

﹥>﹥吖頭↗ 提交于 2020-01-23 10:45:08
问题 I am trying to get my user form to also allow the user to fill out their company profile at the same time via form_for. For some reason it is not showing the company fields. Here is my code for the controller and layouts. class User < ActiveRecord::Base attr_accessible :company_attributes has_one :company accepts_nested_attributes_for :company end class Company < ActiveRecord::Base belongs_to :user # Validation validates :name, :presence => true end <%= f.fields_for :company do |company_form|

accepts_nested_attributes_for causing SQLException

瘦欲@ 提交于 2020-01-23 08:00:27
问题 I would like to use accepts_nested_attributes_for to create an Article object that has_many Sections. class Article < ActiveRecord::Base has_many :sections, :order => "position", :dependent => :destroy belongs_to :categories accepts_nested_attributes_for :sections, :allow_destroy => true, :reject_if => lambda { |attributes| attributes['title'].blank? } validates_presence_of :name, :on => :create, :message => "An article must have a title" end class Section < ActiveRecord::Base belongs_to

uninitialized constant Delayed::Job

风格不统一 提交于 2020-01-23 04:21:48
问题 I've added the delayed_job gem to my gemfile and installed correctly but when I try to run the following line: Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc I get the error 'uninitialized constant Delayed::Job' Can somebody explain what i need to do here? I've tried running 'rake jobs:work' beforehand but it also returns the 'uninitialized constant Delayed::Job' error. Additionally, I've added "require 'delayed_job'" to the file (application.rb) without much luck. 回答1: Did you

Change locale at runtime in Rails 3

a 夏天 提交于 2020-01-23 03:21:10
问题 I am working on a rails 3 app which has different languages in my locales folder. The files are en.yml, pu.yml, sp.yml. All languages have to be converted to their various format and I need help in making users chose any language of their choice with a link like <%= link_to "English language", ...%> <%= link_to "spanish", ...%> When a user choses a language, the language is set as the user's preferred language so that the user does not have to keep selecting a language after each login. 回答1:

Troubles setting up Paperclip + AWS S3 for image storing in our Rails3/Heroku App

断了今生、忘了曾经 提交于 2020-01-23 00:59:05
问题 We have already built a rails app that has several users and an image for each of them. Doing all of the dev work on our localhost, we have working seeds for users & photos...but now that we are trying to use S3 for the image storage, we are running into errors during...always during the "seed" step of the migrations, when doing this: rake db:migrate:reset Apologies for the question, but we have have been banging our heads on this for 11 hours, having gone through every related Stack question