ruby-on-rails-3.2

In Rails, how do I create nested objects using accepts_nested_attributes_for?

大城市里の小女人 提交于 2019-12-22 01:42:26
问题 In my Rails application, I am attempting to set up creation form for a TrainingClass model. I want this form to allow the user to create multiple ClassMeeting models (which have a belongs_to relationship with the TrainingClass model) within the same form, and I am using accepts_nested_attributes_for to do this. Unfortunately, whenever I submit the form I get the error message: Meetings class can't be blank . I realize that this is because ClassMeeting has validates :class_id, presence: true ,

FactoryGirl: Factory not registered

旧时模样 提交于 2019-12-22 01:38:17
问题 I work on a project with a structure like: projects/warehouse/core projects/warehouse/products/bottles projects/warehouse/products/boxes In this project, the application logic, gems, etc. are all in the core application. I have boxes set up for rspec like such: projects/warehouse/products/boxes/spec /factories /models The factories directory contains cubics.rb : FactoryGirl.define do factory :cubic id 1 dimension 12 end end The models directory contains cubic_spec.rb : require 'spec_helper'

Render error on new page with customize url like http://localhost:3000/education_informations/new?user_id=10

╄→尐↘猪︶ㄣ 提交于 2019-12-22 00:35:14
问题 I am trying to pass query parameter with new action http://localhost:3000/education_informations/new?user_id=10 and also set form validation on it. when form submit failed so its display error but url is changes like http://localhost:3000/education_informations so I want to same customize url and pass query parameter with user_id. Please help me controller code give below def create @edu_info = EducationInformations.new(educational_params) if @edu_info.save #flash[:notice] = 'Vote saved.'

Pass Authenticity token through http header

跟風遠走 提交于 2019-12-21 18:44:11
问题 I have a rails application that uses a token to authenticate the user. Currently I am passing the token as params. I would like to change this. I believe it is possible to pass it through html header. I dont understand how to use authenticate_or_request_with_http_token do |token, options| . My rails app is actually a server for my iphone client. I things I dont understand are: I know options is nonce but how will that work out between my client and server? How do I actually use this in my

ActiveRecord :includes - how to use map with loaded associations?

浪子不回头ぞ 提交于 2019-12-21 18:31:12
问题 I have a small rails app, and I'm trying to get some order statistics. So I have an Admin model, and an Order model, with one-to-many association. class Admin < ActiveRecord::Base attr_accessible :name has_many :orders class Order < ActiveRecord::Base attr_accessible :operation belongs_to :admin And I'm trying to get specifical orders using this query: admins = Admin.where(...).includes(:orders).where('orders.operation = ?', 'new gifts!') That works just as expected. But when I try to make

An error occurred while installing libv8 (3.11.8.13), and Bundler cannot continue

梦想的初衷 提交于 2019-12-21 17:18:21
问题 After run bundle install I get this error: Gem::Package::FormatError: no metadata found in /Users/jeanosorio/.rvm/gems/ruby-1.9.3-p286/cache/libv8-3.11.8.13-x86_64-darwin-12.gem An error occurred while installing libv8 (3.11.8.13), and Bundler cannot continue. Make sure that `gem install libv8 -v '3.11.8.13'` succeeds before bundling. I try with gem install libv8 -v '3.11.8.13' But I get ERROR: Error installing libv8: invalid gem format for /Users/jeanosorio/.rvm/gems/ruby-1.9.3-p286/cache

What is `stringify_keys' in rails and how to solve it when this error comes

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 11:20:10
问题 In a partial file of my application I have the following code snippet for displaying user navigation(through Devise):- <ul class="nav pull-right"> <% if user_signed_in? %> <li> <%= current_user.email do %> <i class=" icon-user icon-black"></i> <% end %> </li> <li> <%= link_to "Your Links", profiles_index_path do %> <i class=" icon-user icon-black"></i> <% end %> </li> <li> <%= link_to "Sign out", destroy_user_session_path, :method => 'delete' do %> <i class=" icon-user icon-black"></i> <% end

Setting Content-Type header for RSpec and Rails-API

坚强是说给别人听的谎言 提交于 2019-12-21 08:56:04
问题 I'm using the rails-api gem to build a web service and want to test my API with RSpec. Every request I make, regardless of the HTTP method has the CONTENT_TYPE header set as "application/x-www-form-urlencoded". This isn't really a problem until I try to use wrap_parameters in my controller and it's not have any affect on the params hash: class ApplicationController < ActionController::API include ActionController::ParamsWrapper end class ProjectsController < ApplicationController wrap

Rails render partial with :collection

自作多情 提交于 2019-12-21 07:33:47
问题 This is so simple it shouldnt be an issue but I dont understand whats going on here. I have the following code class DashboardController < ApplicationController def bookings @bookings = Booking.all end end /views/dashboard/bookings.html.erb <%= render 'booking', :collection => @bookings %> /views/dashboard/_booking.html.erb <%= booking.booking_time %> I get the following error undefined method `booking_time' for nil:NilClass However if I do this in /views/dashboard/_bookings.html.erb <%

rake test and error : log writing failed. “\xE2” from ASCII-8BIT to UTF-8

你说的曾经没有我的故事 提交于 2019-12-21 07:10:57
问题 When I run rake test , I get error line every time. log writing failed. "\xE2" from ASCII-8BIT to UTF-8 Please guide on this. How to remove this error. 回答1: You probably have somewhere in your code trying to output string whose encoding is wrong or has some weird characters and the encoding doesn't work. Correct way would be to find the string that results in problems and find out why its in wrong encoding. See encoding and force_encoding in string api (http://ruby-doc.org/core-2.2.0/String