ruby

Multi step form with image uploader

十年热恋 提交于 2021-02-07 02:58:56
问题 I want to build 3 step user registration with avatar uploading on 2nd step. So i follow Ryan Bates's guide http://railscasts.com/episodes/217-multistep-forms . I'm using CarrierWave gem to handle uploads. But it seems like i can't store uploaded file info in user session (i'm getting can't dump File error). I use following technique in controller if params[:user][:img_path] @uploader = FirmImgUploader.new @uploader.store!(params[:user][:img_path]) session[:img] = @uploader params[:user]

cucumber re-run failed scenarios automatically with a tag?

大城市里の小女人 提交于 2021-02-06 15:29:49
问题 In our build there are certain scenarios that fail for reasons which are out of our control or take too long to debug properly. Things such asynchronous javascript etc. Anyway the point is sometimes they work sometimes they don't, so I was thinking it would be nice to add a tag to a scenario such as @rerun_on_failure or @retry which would retry the scenarion X number of times before failing the build. I understand this is not an ideal solution, but the test is still valuable and we would like

cucumber re-run failed scenarios automatically with a tag?

泄露秘密 提交于 2021-02-06 15:26:11
问题 In our build there are certain scenarios that fail for reasons which are out of our control or take too long to debug properly. Things such asynchronous javascript etc. Anyway the point is sometimes they work sometimes they don't, so I was thinking it would be nice to add a tag to a scenario such as @rerun_on_failure or @retry which would retry the scenarion X number of times before failing the build. I understand this is not an ideal solution, but the test is still valuable and we would like

undefined method `reset' for RDoc::TopLevel:Class when installing a new Ruby gem

南笙酒味 提交于 2021-02-06 10:44:14
问题 For example, $ gem install netaddr Fetching: netaddr-1.5.1.gem (100%) Successfully installed netaddr-1.5.1 ERROR: While executing gem ... (NoMethodError) undefined method `reset' for RDoc::TopLevel:Class The NoMethodError exception keeps being raised when I install any new gem. I googled about it and searched issues in RDoc and RubyGems GitHub repositories, but had no luck. My Ruby version is $ ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15] The RubyGems version is $ gem -v

Rails include only selected columns from relation

二次信任 提交于 2021-02-06 10:22:44
问题 I will try to explain: I have a table 'Product' and a table 'Store'. I'm trying to get just the store name to show at the page, but ActiveRecord is returning me all the columns from the store. Here is the code: @product = Product .order(id: :desc) .includes(:store) .select("products.id, products.store_id, stores.name") .limit(1) The built query (from Rails): Processing by IndexController#index as HTML Product Load (0.0ms) SELECT products.id, products.store_id FROM `products` ORDER BY

Rails include only selected columns from relation

被刻印的时光 ゝ 提交于 2021-02-06 10:21:56
问题 I will try to explain: I have a table 'Product' and a table 'Store'. I'm trying to get just the store name to show at the page, but ActiveRecord is returning me all the columns from the store. Here is the code: @product = Product .order(id: :desc) .includes(:store) .select("products.id, products.store_id, stores.name") .limit(1) The built query (from Rails): Processing by IndexController#index as HTML Product Load (0.0ms) SELECT products.id, products.store_id FROM `products` ORDER BY

Rails include only selected columns from relation

蓝咒 提交于 2021-02-06 10:21:30
问题 I will try to explain: I have a table 'Product' and a table 'Store'. I'm trying to get just the store name to show at the page, but ActiveRecord is returning me all the columns from the store. Here is the code: @product = Product .order(id: :desc) .includes(:store) .select("products.id, products.store_id, stores.name") .limit(1) The built query (from Rails): Processing by IndexController#index as HTML Product Load (0.0ms) SELECT products.id, products.store_id FROM `products` ORDER BY

Get time from DateTime Variable in Ruby

a 夏天 提交于 2021-02-06 09:47:09
问题 I am working in ruby, i ahave an object containing today's datetime from database. I only want time truncating the date. How can i get that? 回答1: Try DateTime#strftime. DateTime.now.strftime("%H:%M") # => "12:17" 回答2: #!/usr/bin/ruby -w time1 = Time.now puts "Current Time : " + time1.hour + ":" + time1.min + ":" + time1.sec Taken from & credit to - This TutorialsPoint Post. 回答3: If you use it really often you can use the gem time_splitter to help you set some accessors of date, time, hour and

Get time from DateTime Variable in Ruby

只谈情不闲聊 提交于 2021-02-06 09:46:40
问题 I am working in ruby, i ahave an object containing today's datetime from database. I only want time truncating the date. How can i get that? 回答1: Try DateTime#strftime. DateTime.now.strftime("%H:%M") # => "12:17" 回答2: #!/usr/bin/ruby -w time1 = Time.now puts "Current Time : " + time1.hour + ":" + time1.min + ":" + time1.sec Taken from & credit to - This TutorialsPoint Post. 回答3: If you use it really often you can use the gem time_splitter to help you set some accessors of date, time, hour and

Rendering a JSON object of a join-model and its associated models

喜欢而已 提交于 2021-02-06 09:04:28
问题 In a Rails ( 4.1.5 / ruby 2.0.0p481 / win64 ) application I have a many-to-many relationship between Student and Course and a join model StudentCourse which represents the association, and has an additional attribute called started (set by default on "false"). I also have added an index in the join-table made of student_id and course_id , and set a unique check on that, like this t.index [:student_id, :course_id], :unique => true, :name => 'by_student_and_course' I wanted that to be a