ruby-on-rails-3.2

Rails New SampleApp Hangs forever after Run Bundle Install

流过昼夜 提交于 2019-12-13 08:04:25
问题 While creating new sample project My Rails New Sample hangs forever and does not give controll back to me. On pressing Cntrl + C its asks for terminating Batch job... I am new to ruby On Rails....Please help C:\Sites>rails new MySample2 DL is deprecated, please use Fiddle create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile create app create app/assets/javascripts/application.js create app/assets/stylesheets/application.css create app/controllers

Rails Server Routing Error

家住魔仙堡 提交于 2019-12-13 07:33:33
问题 I am getting a routing error when trying to access the web application with the URL for the localhost. Ruby on Rails 3.2 and Windows 7 is used. The Question: Why does this routing error happen? And does anybody have a suggestion how to fix this? The URL: http://localhost:3000/web_app_name The Error Message: In the Web Browser: Routing Error No route matches [GET] "/web_app_name" In the Command Prompt: Started GET "/web_app_name" for 127.0.0.1 ActionController::RoutingError (No route matches

Writing scope, join and order for a Model

只愿长相守 提交于 2019-12-13 07:21:03
问题 My model is like this: Program has_many Measures and then Measures has_many Targets and Target table has a column named value My query is like this: @programs2 = Program.includes([measures: :targets]) .some_scope .where('organization_id = 1') .limit(2) I don't know where or how to write the some_scope part of the query. The query starts with Program.includes so I think it should be defined in the Program model but the problem I have is that measures: :targets . How do I define a join for them

Attribute available before_type_cast but nil when accessed directly

谁说胖子不能爱 提交于 2019-12-13 07:13:26
问题 I have an ActiveRecord object that has a before_create hook that generates a SHA hash and stores the result in an attribute of the object: before_create :store_api_id attr_reader :api_id def store_api_id self.api_id = generate_api_id end private def generate_api_id Digest::SHA1.hexdigest([Time.now.nsec, rand].join).encode('UTF-8') end This works in that the api_id attribute is created and stored in the database as text (which is forced by the call to .encode('UTF-8') otherwise SQLite will try

How to get jquery animate to work in Rails 3.2.8?

心不动则不痛 提交于 2019-12-13 07:03:17
问题 I am using jQuery's animate() method in my Rails application. However, I can't get it to work. This is my application.js file: //= require jquery //= require jquery_ujs //= require_tree . I tried adding //= require jquery-ui in there but it is causing my application to crash: couldn't find file 'jquery-ui' Can anybody tell me what I am missing? Thanks for any help. 回答1: You need to add 'jquery-ui-rails' in your Gemfile for jquery-ui related plugins to work. Please add the following line to

ActiveModel::MassAssignmentSecurity::Error with nested attributes

泄露秘密 提交于 2019-12-13 06:19:47
问题 Hi im trying to create a relation one-to-many in my rails app. Fist i create my models class Produto < ActiveRecord::Base attr_accessible :compra, :descricao, :estoque, :venda has_many :precos accepts_nested_attributes_for :precos end class Preco < ActiveRecord::Base attr_accessible :compra_decimal, :produto_id, :venda_decimal belongs_to :produto end Then i created my controller class ProdutosController < ApplicationController def new @produto = Produto.new @produto.precos.build end def

specify values in Simple Form Association

假如想象 提交于 2019-12-13 06:16:44
问题 I am trying to select specific record but when trying to save , employee_id is saved with a null value, and without putting any condition it works normally , is there any way to solve this ? <%= f.association :employee , collection: Employee.where('student_advisor' => true).map(&:full_name) %> 回答1: This is what works for me: <%= f.association :employee, :collection => Employee.where('student_advisor' => true), :label_method => :full_name, :value_method => :id %> Though IMHO its better to set

rails 3 how do i submit a remote form with jquery and avoid callbacks

允我心安 提交于 2019-12-13 05:57:17
问题 I have a remote => true form and would like to submit it AND avoid a submit method. Usually i would do form$.get(0).submit() form$.submit(function(){..avoid going here..}) but this sends the form as html instead of js. Any way to do this and get js in response? Thanks! 回答1: Use this code in your controller respond_to do |page| page.js {} end and add a file in your view with controller's function name ending with .js extension. 回答2: man that i was a pain to find. the answer is replace $(form)

Keeps getting “Cannot find Model_name without ID” when writing 'new' method

孤者浪人 提交于 2019-12-13 05:25:43
问题 As background, I currently have three models, School , Course and Section , where they are all in a one-to-many relationships (School has_many courses, and Course has_many sections, with the corresponding belongs_to relationships also established in the model). I also have the following resources (exclusions to be set later): resources :schools do resources :courses end resources :sections #not part of the nest Although sections could work as part of the nested resources, I kept it out since