ruby-on-rails-3.2

Rails 3 - Validation for Time existence

谁说胖子不能爱 提交于 2019-12-24 15:13:28
问题 I have a model with a Time attribute. I want to check that time can not be empty (better choice probably would be to check that input is time but i have no ideas how to deal with that). I tried this validation: # id :integer not null, primary key # school_class_id :integer # meeting_time :time class Meeting < ActiveRecord::Base validates :meeting_time, :presence => { :message => "can't be empty!" } end Then i tried to check this in spec and this fails (empty time is ok but it should not be).

Why is Rails dropping the Postgres connection on large bulk inserts?

本小妞迷上赌 提交于 2019-12-24 14:34:52
问题 I'm brand-spanking new to the world of linux and server administration, and I'm stuck. I have a rails app that occasionally needs to perform large data inserts, usually around 20,000 rows. The code seems to work fine in development (osx), but on the production servers (ubunto, on a linode vps), it fails every time, usually after about 1,700 insertions. The precise number varies (1655, 1697, 1756), but it's consistently in that ballpark. I'm not seeing much that's helpful in the production.log

jQuery “Object function (e,t){return new v.fn.init(e,t,n)} has no method 'on'”

女生的网名这么多〃 提交于 2019-12-24 13:47:17
问题 I'm following @coreyward's example for putting object edit forms in modal dialog windows in Rails, which is outlined in this answer and updated for rails 3.1 in this gist. I'm using Rails 3.2.8 and jQuery-Rails 2.1.3 (jQuery 1.8.2 is what's loading in the app). However, this coffeescript from the gist raises the error in the title, on line 7 (right after the comment). $ -> $modal = $('#modal') $modal_close = $modal.find('.close') $modal_container = $('#modal-container') # Handle modal links

Focus on slider after submitting form with slider

情到浓时终转凉″ 提交于 2019-12-24 13:07:04
问题 I am using the jquery ui slider and when the slider is slid, a form is submitted. The code is as follows: <script type="text/javascript"> $(function() { $( "#slider" ).slider({ min: 2000, max: 2008, value:<%=@epoch.start_year %>, slide: function( event, ui ) { $("#slider_value").html(ui.value); $("form#new_epoch").submit(); } }); }); </script> When I move the slider to a different value, the form submits however when the page reloads the focus on the slider is lost. What I am looking to do is

Why there is no assets/images directory in Rails 4.0 RC1

柔情痞子 提交于 2019-12-24 11:57:21
问题 I just discovered that there isnt a default directory assets/images when I generate a Rails 4 app (Rails 4 rc1 currently). Whereas in Rails 3.1/3.2 its generated. Please tell me why is that so? I mean I can create a directory in a second, but thats not the point. If I didnt get the reason for this on any announcement I am sorry, otherwise it makes no sense to me. Thank you 回答1: Just found out myself that there's no index.html in public any more either because it's done dynamically in Rails 4

Michael Hartl Rails Tutorial (3.2) - Chapter 5 Rspec issue

爱⌒轻易说出口 提交于 2019-12-24 11:32:53
问题 I've completed Chapter 5 and all the exercises. As part of the final exercise, MH has you write tests for the ApplicationHelper method. Once that is done, individual tests pass with: shift-command-T in ST2 (using the sublime-text-2-ruby-tests package) rspec spec/requests/user_pages_spec.rb in the terminal rspec spec/requests/static_pages_spec.rb in the terminal However, if I run all tests with rspec spec/ in the terminal I get this error: /Users/anonymouscoward/rails/railstut/sample_app/spec

Image and print_media_type for pdfkit are not working on rails 4.0.2

走远了吗. 提交于 2019-12-24 11:25:06
问题 I have created a pdf using pdfkit.Pdf is created. But the image is not displaying on my pdf and the print_media_type is also not working. I am using rails 4.0.2 and ruby 2.0.0. can anyone please help me to solve this problem? I am attaching details here. Thank you. gem file: gem 'pdfkit','0.5.2' gem 'wkhtmltopdf-binary','0.9.9.1' gem 'wkhtmltopdf-heroku','1.0.0' application.css : @media print { body { text-align: justify; font-size:566px; background-color: red; } } application.rb: require

twitter bootstrap modal does not work in rails3 layout?

浪尽此生 提交于 2019-12-24 11:07:10
问题 I have a twitter bootstrap modal dialog. I used the example here: http://twitter.github.com/bootstrap/javascript.html#modals and this works well by its self. Works well if I add this to a rails view like index.html.erb of one of my views. Though if I add the same stuff that works to my layout (specifically my navigation one) so that this modal can come down on ANY view in the app, while it works, it never "fades in" it is always behind a darkened screen. I am pulling my hair out trying to

Scope for an optional has_one association with itself

萝らか妹 提交于 2019-12-24 10:44:37
问题 I have a model Indent. On which I am using STI. An indent can be of two types Sale and Purchase. In purchase class I am using an optional has_one association. class Purchase < Indent has_one :sale , :class_name => 'Sale', :foreign_key => 'linked_indent_id' # Make it work. scope :unsold, lambda {includes(:sale).where('id not in (select distinct linked_indent_id from indents)')} end class Sale < Indent belongs_to :purchase , :class_name => 'Purchase', :foreign_key => 'linked_indent_id' end I

rails generate rspec:install returns 'Could not find addressable-2.2.8 in any of the sources'

╄→гoц情女王★ 提交于 2019-12-24 09:59:26
问题 Currently I'm going through the Ruby on Rails Tutorial by Michael Hartl, chapter 3 (http://ruby.railstutorial.org/chapters/static-pages#top), and I'm receiving an error after running the following command: rails generate rspec:install This is the error I'm getting: Could not find addressable-2.2.8 in any of the sources Run 'bundle install' to install missing gems. If I rerun 'bundle install', this is what I get for output: Using rake (0.9.2.2) Using i18n (0.6.0) Using multi_json (1.3.5) Using