ruby-on-rails-3.2

heroku rake db:structure:load failure

时间秒杀一切 提交于 2019-12-05 01:52:26
I need to use some PostgreSQL proprietary features such as rules and triggers for table partitioning. As long as I know, these kind of features cannot be dump to schema.rb so I have changed my schema_format configuration parameter to :sql. Now, when I try to load rake db:structure:load to load the generated structure.sql into the heroku database, it fails saying: sh: psql: not found How can I do it? You can use pg:psql to run the script from your development machine against the database: cd your-rails-project heroku pg:psql -a your-app-name <db/structure.sql Just make sure that the branch you

Rails Minified (Compiled) Assets in development mode

北战南征 提交于 2019-12-05 01:36:38
How do I get my assets rendered in their minified (compiled) form in Rails development mode? I have about few dozens of asset files, and because they are served one after another it all takes pretty long before the page loads in development. I believe if I keep them compiled and getting served from that would speed up my page load time(I know this is not ideal when I am specifically working on assets). Here is my style and script tags in the layout <%= stylesheet_link_tag 'all' %> <%= javascript_include_tag 'all' %> And I've also ran bundle exec rake assets:precompile:nondigest But I still see

How can I use Jquery in rails 3.2.8?

≯℡__Kan透↙ 提交于 2019-12-05 01:27:41
问题 All the tutorials I've read tell me to use the "public/javascripts" folder. But there is no such folder in rails 3.2.8 where do I place my jquery code? isn't Jquery included in Rails 3.2.8? 回答1: The default Rails application (> 3.2) includes the jQuery gem on line 23 of the Gemfile: gem 'jquery-rails' You place your jQuery code in a custom JavaScript file--e.g., hello.js --in the following path: app/assets/javascripts/ Example: app/assets/javascripts/hello.js In hello.js , make sure you

Capybara/RSpec 'have_css' matcher not working but has_css does

不羁岁月 提交于 2019-12-05 01:13:58
In a Rails 3.2.14 app with Ruby 2, using rspec-rails 2.14.0 and capybara 2.1.0 the following feature spec is causing a failure: require 'spec_helper' feature 'View the homepage' do scenario 'user sees relevant page title' do visit root_path expect(page).to have_css('title', text: "Todo") end end The failure message is: 1) View the homepage user sees relevant page title Failure/Error: expect(page).to have_css('title', text: "Todo") Capybara::ExpectationNotMet: expected to find css "title" with text "Todo" but there were no matches. Also found "", which matched the selector but not all filters.

Rendering partials from a helper method

落爺英雄遲暮 提交于 2019-12-05 00:48:17
Is it possible to render a partial using a helper method where you can also pass local variables from the view in which the helper method is called? For example, when I include this code directly in the view, it renders the partial properly: <%= render :partial => "add_round", :locals => { :f => f } %> Then I moved it to a helper method: def addRound render :partial => "add_round", :locals => { :f => f } end Then I called it from the view again with: <%= addRound %> This did not work with the :locals => { :f => f } included in the code. It returned this error: undefined local variable or

Is it possible to sort a list of objects depending on the individual object's response to a method?

时间秒杀一切 提交于 2019-12-05 00:44:20
I am wanting to display a gallery of products where I include products that are both for sale and not for sale. Only I want the products that are for sale to appear at the front of the list and the objects that are not for sale will appear at the end of the list. An easy way for me to accomplish this is to make two lists, then merge them (one list of on_sale? objects and one list of not on_sale? objects): available_products = [] sold_products = [] @products.each do |product| if product.on_sale? available_products << product else sold_products << product end end . . . But do to the structure of

Rails 3.2 - haml vs. erb. Is haml faster? (february 2012)

≯℡__Kan透↙ 提交于 2019-12-04 23:46:53
I am working on a project and I am still thinking about using HAML (beautiful code, less size of view files) instead of classic ERB template. My worries why I didn't do it yet are the speed of generating views - I read an articles/benchmarks and there was almost always HAML slower than ERB - but the truth is, that the articles are 2-3 years old. So my question is, how looks the comparison these two template systems now, in the start of 2012? Here are some benchmarks from someone in Nov 2011 . You should be able to cd to your haml directory and run rake benchmark . I say "should" because you'll

FactoryGirl: Factory not registered

拥有回忆 提交于 2019-12-04 23:02:49
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' describe Boxes::Cubic do it "has a valid factory" do FactoryGirl.create(:cubic).should be_valid end end

Asciifolding not working Elastic Search Rails

痴心易碎 提交于 2019-12-04 22:48:03
问题 I am having a really bad time trying to get " asciifolding " working for my Rails app. I want to search words containing " accented " characters for example i want " foróige " to come up when i search " foroige ". I have tried many things. A couple of them are below. analysis: { analyzer: { text: { tokenizer: "standard", filter: ["standard","lowercase", "asciifolding"], char_filter: 'html_strip' }, sortable: { tokenizer: "keyword", filter: ["lowercase", "asciifolding"], char_filter: 'html

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

帅比萌擦擦* 提交于 2019-12-04 20:14:10
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 , and because TrainingClass can't have an id until after it is saved, but I'm not sure of the right way