ruby-on-rails-3.2

How can I avoid using 'FactoryGirl.reload' due to using 'sequence' in my factories?

微笑、不失礼 提交于 2019-12-25 03:21:50
问题 Having to use FactoryGirl.reload likely to put some overhead on the time it takes to run all tests (when many tests exist) and also it is described as an Anti-Pattern. How can I keep using the sequencing for unique fields, yet test for the correct values? You can see in my code that... I have to call FactoryGirl.reload so that the increment starts at 1 in case any previous tests have already been run. I have to state :count => 1 because there will only ever be one instance of that value. spec

Creating a custom Guestbook Module for Alchemy CMS

扶醉桌前 提交于 2019-12-25 03:04:29
问题 I'm trying to build a guestbook module within a Rails site using the Alchemy CMS framework. There doesn't appear to be much in the way of documentation for module building with Alchemy, so I'm just going off of this page. I've created two controllers, one that admins will use called guestbook_controller.rb and placed this under app/controllers/admin module Admin class GuestbookController < Alchemy::Admin::ResourcesController def index "index" end end end and another for guest to access under

How to use inline :confirm option for html helpers with AJAX calls?

丶灬走出姿态 提交于 2019-12-25 02:56:08
问题 I am trying to have an AJAX implementation of record deletion associated with a button. The problem is that ajax:success event doesn't seem to be triggered in such case. I have implemented the suggestion from this post: Rails :confirm modifier callback?) but I am uncertain if it's the preferred way. I was wondering if communal wisdom could help in this case. What's the right approach here? app/views/competitions/show.html.haml: %td= button_to 'Delete', contender, remote: true, method: :delete

Ensure parent models are the same for a has_many :through association in rails 3.2

◇◆丶佛笑我妖孽 提交于 2019-12-25 02:48:16
问题 I have a Department parent model that is associated with a Product and Document model through a has_many / belongs_to relationship. The Product and Document models are then associated to each other through a has_many :through relationship via a ProductDocuments join model. As part of the associations there is a requirement that the Product and Document models have the same Department parent model when being associated to each other. Right now I'm doing the following:

Rails how to create chart data for each month between 2 dates?

不打扰是莪最后的温柔 提交于 2019-12-25 02:18:50
问题 In my model I have: def self.chart_data(start, slut) if start.nil? start = 2.weeks.ago end if slut.nil? slut = Date.today end range = start.to_date..(slut.to_date + 1.day) if start.to_date.beginning_of_month.to_s != slut.to_date.beginning_of_month.to_s kliks = count( :group => 'date(month)', :conditions => { :created_at => range } ) # CREATE JSON DATA FOR EACH MONTH - PROBLEM HERE (range).map(&:beginning_of_month).uniq.map(&:to_s).each do |month| { created_at: month, clicks: kliks[month] || 0

Add translation to I18N dynamically

回眸只為那壹抹淺笑 提交于 2019-12-25 01:45:04
问题 I have added humanized-money-accessors as described here: Decimals and commas when entering a number into a Ruby on Rails form Now I have two attributes in my model for the same type of data: the original version and the human-readable version. The problem: Since I am using activerecord-translation-yml-files, I have to put in the same translation for original attribute and the humanized_attribute, because my forms show the name of thie humanized_attribute, but on validation errors, the name

List all associated model records present in another model present in another namespace in rails

只谈情不闲聊 提交于 2019-12-25 00:29:35
问题 I have two models like: class Superadmin::Company < ApplicationRecord belongs_to :user has_many :garments end 2nd class Garment < ApplicationRecord belongs_to :company ,:class_name => "Superadmin::Company" end But when I search like company = Superadmin::Company.find(9) company.garments Its give error: as Garment Load (1.3ms) SELECT `garments`.* FROM `garments` WHERE `garments`.`company_id` = 9 ORDER BY created_at asc ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'garments

How to save to Database with associations in rails protecting mass assignment

社会主义新天地 提交于 2019-12-24 22:41:50
问题 After trying for few hours I can not save to the database. The context is this: I have two types of users, one for that I only need very basic information [Username, email, password] and another kind of user for who I need a lot of information [age, gender, city and so on] I did not use STI becouse of the vast quantity of Null values there would be in the table. So I created this three modes in which a user has a profile (profiles table) or not depending of its type [1 or 2], and a field of

how to create select box from a given list in rails?

て烟熏妆下的殇ゞ 提交于 2019-12-24 20:15:07
问题 I am passing a list from my controller @distinct_grade_list = Student.uniq.pluck(:grade) which creates the distinct list of grades from model Student now in my view page , how can i display it as select box I am using <%= collection_select(A, @distinct_grade_list, B, C, D) %> now what do i have to keep at A,B,C,D 回答1: collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) public why not read the api document and sample? sample usage: class

Ransack and namespaced routes… Template missing

亡梦爱人 提交于 2019-12-24 17:34:11
问题 When I search anything I always have the error : Missing template backstage/users/search, application/search with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/RailsApps/novaxones/app/views" I have a User model in app/models class User < ActiveRecord::Base attr_accessible :email, :password, :password_confirmation, :remember_me, :created_by, :active, :blocked, :profile_attributes has_secure_password # relations has_one :profile, :dependent =>