ruby-on-rails-3.2

belongs_to association loaded individually even after eager loading

假如想象 提交于 2019-12-22 10:57:06
问题 I have the below association class Picture < ActiveRecord::Base belongs_to :user end class User < ActiveRecord::Base has_many :pictures end And in my PicturesController i am eager loading the user class PicturesController < ApplicationController def index @pictures = Picture.includes(:user).all end end In my view, i am displaying each pictures user name -@pictures.each do |picture| %tr %td= picture.name %td= picture.user.name Now the question is, even though i am eager loading the user, i see

Rails 4 ckeditor file upload

醉酒当歌 提交于 2019-12-22 10:04:09
问题 I'm using ckeditor in my rails projec and I have a problem with image uploading. I don't want everything that ckeditor have, that I wrote some simple config.js for it: CKEDITOR.editorConfig = (config) -> config.language = 'pl' config.toolbar_Pure = [ '/', { name: 'basicstyles', items: [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, { name: 'paragraph', items: [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','-','JustifyLeft',

In Rails, execute block for both conditions: first_or_create

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 08:15:42
问题 Anybody know a Rails method that will allow me to look for an existing record or create a new one AND execute a subsequent block of code? Example: Model.where(parameters).first_or_create do |m| # execute this regardless of whether record exists or not end Similarly, the method find_or_create_by does not execute a block in either scenario. I could use if-else statements but that will duplicate my code... 回答1: According to the API, the block in your example will only execute if the record does

In Rails, execute block for both conditions: first_or_create

安稳与你 提交于 2019-12-22 08:15:03
问题 Anybody know a Rails method that will allow me to look for an existing record or create a new one AND execute a subsequent block of code? Example: Model.where(parameters).first_or_create do |m| # execute this regardless of whether record exists or not end Similarly, the method find_or_create_by does not execute a block in either scenario. I could use if-else statements but that will duplicate my code... 回答1: According to the API, the block in your example will only execute if the record does

Rails 3.2 app - Should I use a versioning gem (paper_trail or vestal_versions) or handle it manually?

梦想与她 提交于 2019-12-22 07:37:21
问题 My question: Should I roll my own model versioning or use one of the versioning gems that's already out there? If I should use a gem, which one seems best for this application? Info about my app My app is a simple Checklist app. There are Checklists and Jobs, and I track user responses with Responses and Submissions. The Response tells me what the use said ("Done", with a note "We need more mops.") and the Submission tells me when that particular Checklist was filled out (because there may be

Sessions made sense to me before I started reading about them online

对着背影说爱祢 提交于 2019-12-22 06:52:17
问题 The main thing I've gathered from reading about Sessions vs Cookies is that Cookies are stored on the client-side and that sessions are stored on the server-side. If sessions are stored on the server-side, then how does the server ever know which client is theirs? Clearly, something must be on the client-side. Whenever I use my self-rolled user authentication, I have a session_token column in my users database table. Then, this module tends to facilitate sessions for me: module SessionsHelper

Rails 3 routes for nested controllers and sub-folders

余生颓废 提交于 2019-12-22 06:42:29
问题 I need some help with routes for nested controllers. I can't figure out from the Rails guide docs by myself. I have the following controllers in a rails 3.2 app: /app/controllers/organizations_controller.rb (class OrganizationsController) /app/controllers/organization/events_controller.rb (class Organization::EventsController) then, in routes.rb resources :organizations, path: 'org' do resources :events member do get 'confirm' end end end running rake routes shows (only the relevant part for

Rails 3 and rspec - select from select list

心已入冬 提交于 2019-12-22 05:11:35
问题 I want to select value from select list in RSpec . For example i have such data: <div class="control-group"> <label class="control-label" for="user_teacher_leader_attributes_teacher_id">Teacher names</label> <div class="controls"> <select id="user_teacher_leader_attributes_teacher_id" name="user[teacher_leader_attributes][teacher_id]"> <option value="1" selected="selected">Math teacher</option> <option value="2">Physics teacher</option> </div> </div> I want to select option Physics teacher

Could not find i18n-0.6.0 in any of the sources

天涯浪子 提交于 2019-12-22 05:01:23
问题 I just upgraded from Rails 3.0.3 to 3.2.1. The upgrade went smoothly on my Mac but I'm having trouble getting a 3.2.1 instance of my app running on my Ubuntu production server. The error I'm getting is this: Could not find i18n-0.6.0 in any of the sources (Bundler::GemNotFound) Obviously, other people have had this same problem before. Unfortunately, the solution here doesn't fix it for me. Doing sudo bundle install doesn't seem to make a difference. I also found this post but I don't

Rails 3.2: ArgumentError: wrong number of arguments (2 for 1) on create

爷,独闯天下 提交于 2019-12-22 04:31:37
问题 Trying to create an instance of a model, I get the following error... u = User.create # or .where(...).first_or_create # or .where(...).first_or_initialize ArgumentError: wrong number of arguments (2 for 1) Is anyone having the same problem with Rails 3.2? 回答1: Have you overloaded your model's initialize method? In my case, I had overloaded it with: def initialize(attributes=nil) ... end Which I had to fix to: def initialize(attributes = nil, options = {}) ... end In Rails 3.2, the commit