ruby-on-rails-3.1

Facing error installing mysql2 gem

我们两清 提交于 2019-12-22 12:19:53
问题 Rails ask me to succeed with gem install mysql2 and on trying I got the following error.So what is mostly problem with such error? Detail of error is below: Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt

Can multiple objects be inserted with the << operator in Rails 3.1?

拟墨画扇 提交于 2019-12-22 11:34:00
问题 Could I write the following ... raw_data.categories.each do |category| obj.categories << category end As the following instead? ... obj.categories << raw_data.categories 回答1: obj.categories |= raw_data.categories 回答2: Take a look at Array#<< and Array#push . Array#<< takes one which is appended in place to given array. For example: irb> array = %w[ a b c ] # => ["a", "b", "c"] irb> array << 'd' # => ["a", "b", "c", "d"] however, if you pass an array, you'll be surprised at the result irb>

How to select the latest record of each hour in a day

妖精的绣舞 提交于 2019-12-22 11:19:13
问题 I want to select the latest record of each hour in a given date, based on the datetime column 'reading_on'. I have executed the below query hourly_max = InverterReading .where("DATE(reading_on) = ? AND imei = ?", Date.today, "770000000000126") .group("HOUR(reading_on)") .having("max(HOUR(reading_on))") hourly_max.group_by(&:id).each { |k,v| puts v.last.reading_on } In the above query I am not getting the required result. What is the proper way to select the latest record of each hour in a day

How to mock/stub the config initializer hash in rails 3

依然范特西╮ 提交于 2019-12-22 10:31:13
问题 Environment : Rails 3.1.1 and Rspec 2.10.1 I am loading all my application configuration through an external YAML file. My initializer (config/initializers/load_config.rb) looks like this AppConfig = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV] And my YAML file sits under config/config.yml development: client_system: SWN b2c_agent_number: '10500' advocacy_agent_number: 16202 motorcycle_agent_number: '10400' tso_agent_number: '39160' feesecure_eligible_months_for_monthly

Error with MySql while doing Bundle Install

人盡茶涼 提交于 2019-12-22 09:55:27
问题 When I do Bundle Install, I get following error: Installing mysql2 (0.3.10) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/manish/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more

Bourbon vs Twitter Bootstrap for Rails 3.1

女生的网名这么多〃 提交于 2019-12-22 07:07:10
问题 I am looking around at different stylesheet frameworks to pick out which one to use in my Rails 3.1 applicaiton. Twitter Bootstrap looks really cool, but I also see that Bourbon is becoming very popular too. Can anyone give a comparison and pros and cons of each? I am guessing it won't be a good idea to use them both, right? 回答1: You could absolutely use both... Each are a set of SASS mix-ins and CSS classes. You may run into some overlap, but there's nothing that prevents you from using both

Is Rails 3.1 Edge breaking XmlMarkup::Builder?

好久不见. 提交于 2019-12-22 05:33:17
问题 There are a number of examples on the Web (such as http://techoctave.com/c7/posts/32-create-an-rss-feed-in-rails) showing how to make a nice RSS feed using Builder. The canonical template is something like this: xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do xml.title "Your Blog Title" xml.description "A blog about software and chocolate" xml.link posts_url for post in @posts xml.item do xml.title post.title xml.description post.content xml.pubDate post

How to hide html div

点点圈 提交于 2019-12-22 05:33:07
问题 I'm developing a small application in Ruby-On-Rails. I want to hide a div in an html.erb file until a link is clicked. What is the simplest way to do this? 回答1: In your html file: <a href="#" id="show_whatever">Show Whatever</a> <div id="whatever" class="hidden">...</div> In your CSS file: div.hidden { display: none; } In an included javascript file, or inside of <script> tags: $(function() { $('a#show_whatever').click(function(event){ event.preventDefault(); $('div#whatever').toggle(); }); }

How do I precompile assets in rails in development environment?

*爱你&永不变心* 提交于 2019-12-22 05:24:08
问题 I want to manually precompile some assets in my dev environment (to check the content of the compiled js and css files) from the command line. I am running RAILS_ENV=development bundle exec rake assets:precompile but my js and css are not compiled in the public/assets folder, only the images are. Any idea why that may be happening? 回答1: Try adding this to your config/environments/production.rb : config.assets.precompile += %w( *.css *.js ) 来源: https://stackoverflow.com/questions/10081832/how

Simple way to always make a field lowercase in db

点点圈 提交于 2019-12-22 05:13:04
问题 Currently I'm doing the following in the model: before_save :to_lower before_create :to_lower def to_lower self.name = self.name.downcase end Seems pretty repetitive to me. 回答1: You don't need the before_create if you already have before_save. before_save { |user| user.name = user.name.downcase } 回答2: I generally handle such cases by: def name= name super(name.try(:downcase)) end 回答3: def name=(val) write_attribute(:name, val.downcase) end 回答4: Why are you doing this? If it's to perform case