ruby-on-rails-4

CarrierWave Backgrounder process leaves denied access to s3 image

旧城冷巷雨未停 提交于 2020-02-08 09:14:22
问题 My current Sidekiq setup with the following is processing the image, but nothing is being done in the background. The page takes 10 seconds to load and then the new image is shown on the redirected page with the following path. https://d9vwx0ll7rhpx.cloudfront.net/development/photo/image/product_thumb/product_thumb_0046d4ca-ca8d-4c02-b8cd-da0255c5736e.jpg I would like for this process to be done in the background. def create @photo = Photo.new(photo_params) if @photo.save UploadsWorker

ERROR - Guard::RailsAssets failed to achieve its <start>, exception was (Rails 4/ zeus/guard)

青春壹個敷衍的年華 提交于 2020-02-07 17:14:02
问题 I am getting this error whenever I load Guard and I think it fails to precompile locally my assets due to this. When I load guard with $ guard I get: 16:55:35 - ERROR - Guard::RailsAssets failed to achieve its <start>, exception was: > [#6D5274147654] TypeError: can't modify immutable index > [#6D5274147654] /home/mathieu/.rvm/gems/ruby-2.0.0-p451@rails3tutorial2ndEd/gems/sprockets-2.12.3/lib/sprockets/index.rb:81:in `expire_index!' > [#6D5274147654] /home/mathieu/.rvm/gems/ruby-2.0.0-p451

Precompilation breaking on heroku, works locally

痞子三分冷 提交于 2020-02-07 05:44:07
问题 I did some restructuring of our less files. Everything works locally (e.g. rake assets:precompile ), but on Heroku my push fails with the following: Running: rake assets:precompile adding placeholder rake aborted! Less::ParseError: variable @brand-primary is undefined (in /tmp/build_24298d78-579f-44a3-ae43-c4d82b9dde9d/app/assets/stylesheets/lectures/lectures.less) at /tmp/build_24298d78-579f-44a3-ae43-c4d82b9dde9d/vendor/bundle/ruby/2.1.0/gems/less-2.5.1/lib/less/js/lib/less/parser.js:604:31

Controller can't find object created by worker

假如想象 提交于 2020-02-06 05:49:05
问题 Spent all day trying to fix this.. Basically the controller is calling worker to perform the creation of "Balance". The worker performs with success and the record is created but when it returns to the controller it can't find the object created. How to force it looking for the "updated database" records ? Controller: balance = BalanceCreator.perform_async(userx.id, market.id) 20.times do status = Sidekiq::Status::get balance, :exp_status if ["done"].include?(status) break end sleep(0.2) end

Rails 4 using controller concern to DRY update methods

扶醉桌前 提交于 2020-02-06 04:54:54
问题 I have a rails app where many of the models are editable using best_in_place, so I have a lot of controllers that look partially like this: before_action :find_objects, except: [:new, :create] def update @object.update_attributes(object_params) respond_to do |format| format.json { respond_with_bip @object} end end private def object_params params.require(:object).permit(:foo, :bar) end def find_objects @object = Object.find(params[:id]) end How do I move this particular repeated piece into a

Rails 4 using controller concern to DRY update methods

只愿长相守 提交于 2020-02-06 04:54:21
问题 I have a rails app where many of the models are editable using best_in_place, so I have a lot of controllers that look partially like this: before_action :find_objects, except: [:new, :create] def update @object.update_attributes(object_params) respond_to do |format| format.json { respond_with_bip @object} end end private def object_params params.require(:object).permit(:foo, :bar) end def find_objects @object = Object.find(params[:id]) end How do I move this particular repeated piece into a

Rails 4 using controller concern to DRY update methods

匆匆过客 提交于 2020-02-06 04:54:09
问题 I have a rails app where many of the models are editable using best_in_place, so I have a lot of controllers that look partially like this: before_action :find_objects, except: [:new, :create] def update @object.update_attributes(object_params) respond_to do |format| format.json { respond_with_bip @object} end end private def object_params params.require(:object).permit(:foo, :bar) end def find_objects @object = Object.find(params[:id]) end How do I move this particular repeated piece into a

Create multiple records using single form (Not nested attributes)

倾然丶 夕夏残阳落幕 提交于 2020-02-05 02:36:07
问题 In my application I have a Thought model which has content and author attributes. I want to create multiple thoughts at once using new form. But this is not a case of nested forms as i am not using any associated models. Please suggest some solution. Thanks in advance! 回答1: You can try with the below solution In your View File <%= form_tag your_action_path do %> <% 4.times do |i|%> Content : <%= text_area_tag :thought_content, "", :name => "thoughts[][content]" %> Author : <%= text_field_tag

How to show online users

こ雲淡風輕ζ 提交于 2020-02-03 09:43:50
问题 I'm writing a simple chat, and I need to list out users online. I don't use devise for authentication, there's a custom user model which authenticates via omniauth . user.rb class User < ActiveRecord::Base has_many :messages, dependent: :delete_all class << self def from_omniauth(auth) provider = auth.provider uid = auth.uid info = auth.info.symbolize_keys! user = User.find_or_initialize_by(uid: uid, provider: provider) user.name = info.name user.avatar_url = info.image user.profile_url =

Allow only specific emails to register in Rails app (Devise)

拥有回忆 提交于 2020-02-03 08:27:11
问题 I am using Devise to authenticate and register users in my Rails app. However, I only want users who have an email with a specific ending to be able to sign up and access it (let's say @xyz.com). What do I need to do to reflect that? 回答1: If you want to restrict users access after the registration use before_filter: before_filter :verify_email private def verify_email (redirect_to(root_path) unless current_user.email.include?('@xyz.com') end Edit: if you want to restrict registration you