ruby-on-rails-3.2

What does mean <top (required)> in rspec?

杀马特。学长 韩版系。学妹 提交于 2019-12-14 02:32:50
问题 I have some rspec test. For example require 'spec_helper' describe UsersController do before (:each) do @user = FactoryGirl.create(:user) sign_in @user end describe "GET 'show'" do it "should be successful" do get :show, :id => @user.id response.should be_success end it "should find the right user" do get :show, :id => @user.id assigns(:user).should == @user end end end When I run the rspec i get some errors Failures: 1) UsersController GET 'show' should be successful Failure/Error: @user =

Rails Ransack - How to search multiple values

前提是你 提交于 2019-12-14 02:32:12
问题 Using the Ransack gem I was able to implement a search using checkboxes for certain values. However, this doesn't work with more than one checkbox. What am I missing? View: <%= search_form_for @search do |f| %> Part Time:<%= check_box_tag "q[job_type_cont]", value = "Part time" %></br> Full Time:<%= check_box_tag "q[job_type_cont]", value = "Full time" %></br> <%= f.submit "Search" %> <% end %> Index Action: def index @search = Job.search(params[:q]) @jobs = @search.result end 回答1: Your view

Following Ruby-on-Rails tutorial and getting 'destroy users' doesn't work

本秂侑毒 提交于 2019-12-13 18:45:43
问题 I've recently installed Ruby on Rails 3.2 and have been trying to learn it. I've been following along with the RoR 3.0 tutorial (http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users#top) and so far it is going well (yes I know there's a 3.2 version). Currently I am stuck on section 10.4.2 which teaches how to add a link to destroy users. It says to add the code <%= link_to "delete", user, :method => :delete, :confirm => "You sure?", :title => "Delete #{user.name}" %> As

Nested attributes not saving in database? Does not display values - Ruby on Rails

独自空忆成欢 提交于 2019-12-13 17:15:06
问题 I have a nested attribute and I can display values, but it is not saving into database why? I have a model review and I want to nest attribute comments review migration file class CreateReviews < ActiveRecord::Migration def change create_table :reviews do |t| t.belongs_to :reviewable, polymorphic: true t.timestamps end add_index :reviews, [:reviewable_id, :reviewable_type] end end review model class Review < ActiveRecord::Base attr_accessible :rating, :user_id, :comments_attributes, :service

Custom message with validates presence of not working

被刻印的时光 ゝ 提交于 2019-12-13 16:30:29
问题 My User model contains the following: validates :password_digest, :presence => true, :message => "The password has to be 6 or more characters long" def password=(password) self.password_digest = BCrypt::Password.create(password) if password.length >= 6 end The issue is that the message in the validates isn't working. I get a Unknown validator: 'MessageValidator' error. I assumed the way the presence validation worked was that it would just check if the password_digest was nil , which it would

Rails generators not generating the proper test templates

人盡茶涼 提交于 2019-12-13 12:33:33
问题 My project lives here: https://github.com/jonesdeini/ICanHazSandvich I'm getting setup using minitest-rails add I can't get the generators to generate the correct test templates. from my application.rb: config.generators do |g| g.test_framework :mini_test, :spec => true, :fixture => false end even with "g.test_framework nil" I still get the same test templates generated: Output: rails g model Foo invoke active_record create db/migrate/20120827160129_create_foos.rb create app/models/foo.rb

Validate on inclusion within array of options OR be nil

大城市里の小女人 提交于 2019-12-13 11:57:04
问题 I have a model where I'd like to restrict input for a field to either be nil or fall within a specified array of values. I can get the inclusion part working, but the allow_nil: true bit doesn't seem to work for me: class Mock::Patient < ActiveRecord::Base LANGUAGE_OPTIONS = %w[English Spanish French German Chinese Hindi Punjabi] validates :preferred_language, inclusion: { in: LANGUAGE_OPTIONS } end I've tried modifying that last line to things like: validates :preferred_language, inclusion:

rails activesupport notifications - wrong db runtime value

做~自己de王妃 提交于 2019-12-13 11:55:59
问题 I'm trying to log requests for my REST API application. I'm using rails notifications for this , like here http://railscasts.com/episodes/249-notifications-in-rails-3 I can't understand how to solve one problem with rails notifications. my initializer code ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload| p name p start p finish p id p payload end Controller respond section class PostsController < ApplicationController # GET /posts

How to do recurring deposit calculations accurately [closed]

自古美人都是妖i 提交于 2019-12-13 09:03:51
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I'm new to ruby on rails and my doubt is how to do recurring deposit calculations. i have used one formula to calculate monthly interest and that is working for first month and not calculating accurate interest for the upcoming months(2nd month, 3rd month ... n months). Formula i used is given

Navigating through relations on two paths in schema

Deadly 提交于 2019-12-13 08:47:06
问题 From top to bottom I have the belongs_to relationship between my tables , and well has_many from the other direction. ReportTarget Report Manager Organization and Score Manager Organization so notice that Report table and Score table are kind of on the same level. They both have Manager Table as their parent. Individually I could figure out how to navigate them with eager loading. For first one I will do: @blah = Organization.includes(managers: { reports: :report_targets }).find(params[:id])