ruby-on-rails

Rails Jquery compute total from selected checkboxes in a table

懵懂的女人 提交于 2021-02-19 05:29:31
问题 So here is my rails view which has a form which pulls the product_items and lets the user check all the items they want to buy and display the total order amount underneath the table. (attached pic) My code looks like below. The server side is good (where I can save the order) but I need some help on the client side js to compute the order total and displaying the order total underneath the table. <tbody> <% @cause.product.product_items.each do |item| %> <tr> <td width="60%"><label class=

How do I validate certain fields with rails devise on registration only

拈花ヽ惹草 提交于 2021-02-19 04:06:55
问题 I have a set of custom fields attached to a devise model called Entrant. I have two forms, one for registration form (three fields) and one which sits in the account area (12 fields). Most of the custom fields area required but only within the form the sits in the account area. How do I achieve this? I am using rails 4.2 and ruby 2.1 回答1: You can simply specify validations on actions, that is: validates :name, presence: true, on: :create # which won't validate presence of name on update

How do I validate certain fields with rails devise on registration only

让人想犯罪 __ 提交于 2021-02-19 04:04:31
问题 I have a set of custom fields attached to a devise model called Entrant. I have two forms, one for registration form (three fields) and one which sits in the account area (12 fields). Most of the custom fields area required but only within the form the sits in the account area. How do I achieve this? I am using rails 4.2 and ruby 2.1 回答1: You can simply specify validations on actions, that is: validates :name, presence: true, on: :create # which won't validate presence of name on update

Custom validation on nested attributes

跟風遠走 提交于 2021-02-19 04:03:08
问题 I need to find a way to get rails (3.2.8) to save nested attributes before performing validation on the parent object. I've searched a long time for an answer to my problem and, while I've found similar questions, I haven't yet seen an elegant solution. Here's the situation: I have an activity_log where each log_entry has multiple activities. The log_entry has a field called 'hours', which represents the total time worked that day. Each activity also has an 'hours' field, representing time

Rails sees mysql tinyint(1) as a boolean - but I want it to be a number

我与影子孤独终老i 提交于 2021-02-19 03:43:09
问题 Rails 4.2.1 using mysql2 gem. ActiveRecord treats a mysql column with data type tinyint(1) as a boolean. But I want to use it as a small number - I want to store values up to 100 which is ok for tinyint(1) . When I try to create a record, the tinyint column casts to false and I get a depreciation warning: > Foo.create(my_tinyint_col: 13) (0.2ms) BEGIN SQL (0.5ms) INSERT INTO `foos` (`my_tinyint_col`) VALUES (0) (107.3ms) COMMIT => #<Foo ID: 519, my_tinyint_col: false> DEPRECATION WARNING: You

counter_cache not decrementing for has_many associations in ActiveReord

非 Y 不嫁゛ 提交于 2021-02-19 03:43:09
问题 My Rails 3 app has 2 models and a third that's join table between them and their has_many relationships. Basically, User and Show are joined by SavedShow, allowing users to save a list of shows: class Show < ActiveRecord::Base has_many :saved_shows has_many :users, :through => :saved_shows end class User < ActiveRecord::Base has_many :saved_shows has_many :shows, :through => :saved_shows end class SavedShow < ActiveRecord::Base belongs_to :user, :counter_cache => :saved_shows_count belongs_to

Rails: rake db:migrate *very* slow on Oracle

泄露秘密 提交于 2021-02-19 03:22:32
问题 I'm using rails with the oracleenhanced adaptor to create a new interface for a legacy application. Database migrations work successfully, but take an incredibly long amount of time before rake finishes. The database changes happen pretty quickly (1 or 2 seconds), but the db/schema.db dump takes over an hour to complete. (See example migration below.) It's a relatively large schema (about 150 tables), but I'm sure it shouldn't be taking this long to dump out each table description. Is there

before_create doesn't work in rails

爱⌒轻易说出口 提交于 2021-02-19 02:42:27
问题 In a rails project, I have 3 controllers and models, user, responsibility and profile. I have below code: user.rb class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_one :responsibility has_one :profile before_create :build_responsibility before_create :build_profile end responsibility.rb class

Rails: pagination with custom offset using Kaminari

梦想与她 提交于 2021-02-19 02:41:05
问题 I'm using Kaminari for pagination and under a certain situation need the first page to contain only 2 entries while each other to have 6. Thought this was achievable using padding() , but it doesn't seem to work like I'd expect (the documentation doesn't help much either): a = (1..20).to_a b = Kaminari.paginate_array(a).page(1).per(6).padding(2) => [3, 4, 5, 6, 7, 8] Any ideas on how to accomplish this? 回答1: this might help you: a = (1..20).to_a b = Kaminari.paginate_array(a).page(1).per(6)

How to send two different emails for devise confirmable and devise reconfirmable?

…衆ロ難τιáo~ 提交于 2021-02-19 01:34:53
问题 Both devise confirmable (email confirmation when user signs up) and reconfirmable (email confirmation when user changes email) modules send the same email template, "confirmation_instructions". How do I get it so that a different email template is used for confirmable? 回答1: You can override options[:template_name] in the #confirmation_instructions method of your mailer. class AuthMailer < Devise::Mailer helper :application include Devise::Controllers::UrlHelpers default template_path: 'devise