ruby-on-rails-4

Convert String to date of specific timezone

谁都会走 提交于 2020-01-17 14:00:29
问题 I need to convert a string to date in a specific timezone. Eg. from = "June 13, 2015" Date.strptime(from,"%b %d, %Y") #=> Sat, 13 Jun 2015 Date.strptime(from.strip,"%b %d, %Y").in_time_zone("America/Chicago") #=> Sat, 13 Jun 2015 00:00:00 CDT -05:00 which is ActiveSupport::TimeWithZone format Date.strptime(from,"%b %d, %Y").in_time_zone("America/Chicago").to_date #=>Sat, 13 Jun 2015 which is in UTC Date class I need the final date in America/Chicago timezone. How can I achieve that? I need to

no implicit conversion of Symbol into Integer when migrating in production

百般思念 提交于 2020-01-17 12:12:46
问题 So I'm working on an existing app and for some reason I was able to get it working and mirrored on my local environment however when I try migrating on heroku I get the below error, any ideas? Error: == 20141119113015 CreateReleasedInventoryStatus: migrating ==================== -- create_enum("eh_released_inventory_status", ["rejected", "pending", "allocated", "released", "transferred"]) rake aborted! StandardError: An error has occurred, this and all later migrations canceled: no implicit

no implicit conversion of Symbol into Integer when migrating in production

北城余情 提交于 2020-01-17 12:12:31
问题 So I'm working on an existing app and for some reason I was able to get it working and mirrored on my local environment however when I try migrating on heroku I get the below error, any ideas? Error: == 20141119113015 CreateReleasedInventoryStatus: migrating ==================== -- create_enum("eh_released_inventory_status", ["rejected", "pending", "allocated", "released", "transferred"]) rake aborted! StandardError: An error has occurred, this and all later migrations canceled: no implicit

Rails 4 not right path for image_url

江枫思渺然 提交于 2020-01-17 11:17:27
问题 So, my next problem on a rails project is the following: I am using the asset pipeline to serve my assets. Now I want to include inline css into a view with a background image. because of the asset pipeline I am just able to use the helpers that rails offers from ground. But the problem is, that every helper (except image_tag is delivering the wrong output). image_url('work-1.png') # => /images/work-1.png image_path('work-1.png') # => /images/work-1.png asset_url('work-1.png') # => /work-1

Ruby/Rails - Accessing params values

China☆狼群 提交于 2020-01-17 09:11:13
问题 A newbie question I assume but here we go: I have the following params: {"utf8"=>"✓", authenticity_token"=>".........", "import"=> {"csv"=> #<ActionDispatch::Http::UploadedFile:0x007fb59092a660 @content_type="text/csv", @headers="Content-Disposition: form-data; name=\"import[csv]\"; filename=\"Users.csv\"\r\nContent-Type: text/csv\r\n", @original_filename="DemoUsers.csv", @tempfile=#<File:/var/folders/_p/w29hlx3x0cs6h026txv_rqhc0000gn/T/RackMultipart20141211-8204-1ha0i1u>>, "datatype"=>"users

How build a advanced search with checkbox using Ransack?

為{幸葍}努か 提交于 2020-01-17 07:32:46
问题 how I build a advanced search how this image: I have my controller, very basic yet: def index @q = Product.ransack(params[:q]) @products = @q.result(distinct: true) end And have my view: <%= search_form_for @q do |f| %> <%= f.label :name_cont, "Name" %> <br /> <%= f.search_field :name_cont %> <br /> <%= f.label :brand, "Brand" %> <br /> <%= f.collection_check_boxes :brand, Product.all, :id, :brand %> <br /> <%= f.label :hd, "HD" %> <br /> <%= f.collection_check_boxes :hd, Product.all, :id,

Use value in override error message in Rails 4 for custom Validator

落花浮王杯 提交于 2020-01-17 07:07:34
问题 I am on Rails 4.2 I have written a custom Validator which will check if a value being entered exists in another table. I have been reviewing some other posts and it seems there is either a context specific or rails version preferred way to reuse the value being validated. In the rails docs i see examples such as: validates :subdomain, exclusion: { in: %w(www us ca jp), message: "%{value} is reserved." } however, if I try to use %{value} in my custom message override it does not interpolate,

Use value in override error message in Rails 4 for custom Validator

别等时光非礼了梦想. 提交于 2020-01-17 07:06:30
问题 I am on Rails 4.2 I have written a custom Validator which will check if a value being entered exists in another table. I have been reviewing some other posts and it seems there is either a context specific or rails version preferred way to reuse the value being validated. In the rails docs i see examples such as: validates :subdomain, exclusion: { in: %w(www us ca jp), message: "%{value} is reserved." } however, if I try to use %{value} in my custom message override it does not interpolate,

rails ams, Nested models undefined method `' for nil:NilClass

对着背影说爱祢 提交于 2020-01-17 05:46:46
问题 I have the following models: class Appeal < ActiveRecord::Base belongs_to :applicant, :autosave => true belongs_to :appealer, :autosave => true end class Appealer < ActiveRecord::Base has_many :appeals, :autosave => true end class Applicant < ActiveRecord::Base has_many :appeals end What I want is for every appealer to hold a reference to the applicant of his last appeal so I modified Appealer model to: class Appealer < ActiveRecord::Base has_many :appeals, :autosave => true def last

Rails 4 Minitest Testing Virtual Attributes

邮差的信 提交于 2020-01-17 05:38:22
问题 So I have a class TimeBank, and its being updated, and is getting two new virtual attributes which will manipulate two other existing attributes (DB columns). class TimeBank < ActiveRecord::Base # validations, consts, few other methods omitted for brevity def date_worked @date_worked ||= self.start.to_date rescue Date.current end def date_worked=(date_worked_val) self.attributes['date_worked'] = date_worked_val end def hours_worked @hours_worked ||= hours rescue NoMethodError nil end def