ruby-on-rails-3.2

Factory already registered: user (FactoryGirl::DuplicateDefinitionError)

给你一囗甜甜゛ 提交于 2019-12-03 04:11:28
Description of problem: - I've setup factory_girl_rails however whenever I try and load a factory it's trying to load it multiple times. Environment: - rails (3.2.1) - factory_girl (2.5.2) - factory_girl_rails (1.6.0) - ruby-1.9.3-p0 [ x86_64 ] > rake spec --trace ** Execute environment -- Creating User Factory -- Creating User Factory rake aborted! Factory already registered: user The only other thing I've changed is: /config/initializers/generator.rb Rails.application.config.generators do |g| g.test_framework = :rspec g.fixture_replacement :factory_girl end GEMFILE gem 'rails', '3.2.1' #

Can I run a Rails engine's specs from a real app which mounts it?

混江龙づ霸主 提交于 2019-12-03 03:51:25
I have a Rails Engine meant to provide some models and controllers to a larger project of ours. There's a pretty decent set of specs for the Engine, using a bunch of mocks and some full-scale models and controllers within the engine's dummy app to make sure the Engine is doing what it's supposed to and working with the larger application. However, even with all tests passing, I frequently find broken behavior when I update the engine in the larger application. If my tests are passing but the behavior is broken, clearly something's wrong with the tests, but what? Am I mocking too much, or not

Rails remote delete and update view through Ajax

北战南征 提交于 2019-12-03 03:32:45
In the past, whenever I wanted to update a part of my view through Ajax, I've done the following: create a partial out of the part I want to update and give it a unique ID, say #tracks create a special action in the controller for that Ajax call, say remove_track that updates all the values, etc. and add format.js create a new JS file with the same name as the action so Rails calls it automatically remove_track.js.erb which contains something like: $('#tracks').html("<%=j render 'cds/show_tracks' %>"); set remote: true in the link that calls this action. All this is fine, but now I am trying

How to do render partial on jQuery ajax success method with rails 3

丶灬走出姿态 提交于 2019-12-03 03:20:47
问题 I'm using rails 3.2.1 with jQuery for an ajax call. My jQuery code is : jQuery.ajax({ url: "/org_pages", data: 'org_id='+ org_id, type: "POST", success: function(result){ jQuery("#image_center").html("<%= escape_javascript(render(:partial => 'pages/top_link')) %>"); }, error: function(){ alert('Error occured'); } }); My problem is on the web page the output is showing this : <%= render :partial => 'pages/top_link', :collection=>@pages %> How it should display my render partial page. :( 回答1:

How can I make Rails 3 assets precompile faster?

你。 提交于 2019-12-03 03:10:22
问题 I have a running Rails 3.2.1 application, that I'm deploying via Capistrano with the deploy/assets which runs the deploy:assets:precompile task. Everything works just fine, except that the compilation itself is really slow. I don't have that much CSS and JavaScript (about 8200 lines total). It generally takes about 1-3 minutes to compile the assets, which is about 90% of the whole deployment time. Is there any way to optimize this? Maybe use a different procedure to compile the assets or

Sending files to a Rails JSON API

元气小坏坏 提交于 2019-12-03 03:08:18
问题 I know there are questions similar to this one, but I've not found a good answer yet. What I need to do is send a description of an object to one of my create methods, which includes some different attributes including one called :image, a paperclip attachment: has_attached_file :image Now I've read that sending the image could be done straight in JSON by encoding and decoding the image as base64, but that feels like a dirty solution to me. There must be better ways. Another solution is

How to deal with vendor/plugins after upgrading to rails 3.2.1

纵然是瞬间 提交于 2019-12-03 03:08:07
问题 After upgrading to rails3.2.1,this warning occurs: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released I move my plugins in vendor/plugins directory but i don't know how to write config/initializers

How to debug a Rails asset precompile which is unbearably slow

a 夏天 提交于 2019-12-03 02:36:50
问题 I'm working on a Rails 3.2 project and the assets have increased a fair bit in recent months although I wouldn't consider the project to be large. The assets consist of JS (no coffee-script), and SASS files; we've quite a few images but they've been there more less since the early days so I don't think they are a substantial factor. We may have about a dozen libs and most are small, the largest is Jquery UI JS. Deployment is done via Capistrano and it started to become apparent that deploying

Adding parameter to a scope

自闭症网瘾萝莉.ら 提交于 2019-12-03 02:30:01
I have a ActiveRecord query for example like this: @result = stuff.limit(10) where stuff is a active record query with where clauses, order by, etc... Now I thought why to pass magic numbers like that to the controller? So do you think is it a good practice to define a scope for "limit(10)" and use that instead? and how would the syntax look like? The scope would look like any other (although you may prefer a class method), e.g., class Stuff < ActiveRecord::Base def self.lim limit(3) end end > Stuff.lim.all => [#<Stuff id: 1, name: "foo", created_at: "2013-03-01 17:58:32", updated_at: "2013-03

Rails emits warning: “Rack::File headers parameter replaces cache_control after Rack 1.5”

做~自己de王妃 提交于 2019-12-03 01:58:23
I've recently upgraded my Rails to v3.2. The server starts and works, however I'm noticing the following warning: Rack::File headers parameter replaces cache_control after Rack 1.5. In my development.rb I have the following configuration for cache control: config.static_cache_control = "public, max-age=36000" What does the warning mean and what should I do to address it? The warning is caused by a call from within Rails itself . The warning has been fixed in Rails 3.2.13 . You have to upgrade Rake file. This issue occurred in Rails 3.2.12 but solved in Rails 3.2.13 to solve this issue. You