ruby-on-rails-3.2

heroku rake db:structure:load failure

僤鯓⒐⒋嵵緔 提交于 2019-12-06 20:20:59
问题 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? 回答1: You can use pg:psql to run the script from your development machine against the database:

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

五迷三道 提交于 2019-12-06 19:17:58
问题 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

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

一世执手 提交于 2019-12-06 19:13:41
问题 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

Rails Minified (Compiled) Assets in development mode

只谈情不闲聊 提交于 2019-12-06 18:44:48
问题 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' %> <%=

Why won't Rails find my assets?

对着背影说爱祢 提交于 2019-12-06 18:43:46
问题 When in production mode, rails can't seem to find any precompiled assets from the asset pipeline. I'm using rails 3.2.0 and ruby 1.9.3 running inside RVM on CentOS. No additional web server is running in conjunction with this application. The application was only recently updated to use the asset pipeline, as it was originally a rails 3.0 app. After running rake assets:clean rake assets:precompile I see the hashed content in public/assets, as I would expect. The hashes at the end of the files

NameError: uninitialized constant ActionController::Dispatcher

谁说胖子不能爱 提交于 2019-12-06 15:38:00
Found a similar post here but I am running a Mac so the first solution does not exactly apply and the second didn't work for me. Running Mac OS 10.7.2, Xcode 4.2.1, rvm 1.10.1 using ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] I believe the issue to due with rvm, however I do not know how to fix it $ rails new dispatch_me $ rails generate controller demo index $ rails console Loading development environment (Rails 3.2.0.rc2) 1.9.3-p0 :001 > env = {} => {} 1.9.3-p0 :002 > env['REQUEST_METHOD'] = 'GET' => "GET" 1.9.3-p0 :003 > env['PATH_INFO'] = '/demo/index' => "/demo/index" 1

Is it possible to order multiple columns by using the `ORDER BY FIELD` statement?

大兔子大兔子 提交于 2019-12-06 14:26:14
问题 I am using Ruby on Rails 3.2.2 and I would like to know if it is possible to order multiple columns/fields by using the ORDER BY FIELD statement (for example, as made in the Model.order("orders_count, created_at, name, ...") but for ORDER BY FIELD ). If so, how can I " ORDER BY FIELDS "? P.S. : As written in a previous answer, in order to order my records relating to one column I am using the Model.order("field(status, 'blocked', 'unpublished', 'published')") statement. 来源: https:/

How to get content type of a given url inside Javascript?

房东的猫 提交于 2019-12-06 14:21:45
I want to know the content type of a given url input by the user inside my Javascript code. Actually, I have a drop-down list (html,csv,xls etc.) and I want to make it so when the user inputs an url, I want to detect the type of the content of the url and based on this type I want to set the value of my drop-down list (html,csv,xls etc.). I know, I can get the content type using Ruby like this : require 'open-uri' str = open('http://example.com') str.content_type #=> "text/html" or, also, I could use curl to get the content and then parse it to know the content type. But, I need to do this

How to change the default value of check_box ? in Ruby on Rails

不问归期 提交于 2019-12-06 13:27:52
How to change the default value of check_box ? views/doctors/_form.html.erb <%= form_for(@doctor) do |f| %> <%= f.label :pass %><br> <%= f.check_box :pass, {checked: true, checked_value: "yes", unchecked_value: "No"} %> <%= f.submit %> <% end %> The data type of :pass attribute was string , But still it was not created any value for :pass attribute in DB. So, I changed the data type of :pass attribute into boolean. Now it is working with True and False But, I Just want to change the True and False into Yes and No Please someone help me. According to this , the correct syntax is: check_box

Hirb doesn't work at all in rails console

纵饮孤独 提交于 2019-12-06 13:27:29
问题 I followed the tutorial on hirb rdoc but unfortunately, my rails console is not working at all. I've already done sudo gem install hirb and added hirb to my Gemfile: gem 'hirb', '~>0.7.0' Then I launched bundle install And I get this result : rails c Loading development environment (Rails 3.2.11) > require 'hirb' => false > Hirb.enable => true > Municipality.all Municipality Load (0.8ms) SELECT "municipalities".* FROM "municipalities" ORDER BY name asc => [#<Municipality id: 1, district_id: 6