How to post an image/file using Rails, AngularJs and Grape Api Posted: 04 Aug 2016 07:54 AM PDT Anybody has any idea how to upload image using Paperclip gem and AngularJS via Grape Api and Interactors? My interactor (without params): def execute create_item! end def create_item! @item ||= Item.create({ location: location, comments: comments, contact_person: contact_person, status_string: status_string, adress: adress, period: period, region: region, postcode: postcode, media_type: media_type, price: price, area: area, width: width, height: height, }) end My AngularJS code in controller: $scope.upload = (file) -> if (file) Upload.upload({ file: file url: '/api/v1/frontend/items/' }).progress( (evt) -> progressPercentage = parseInt(100.0 * evt.loaded / evt.total); console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name); ).success (response) -> console.log('succes') API GRAPE desc 'Post a item' params do requires :item, type: Hash do requires :location, type: String requires :area, type: Float requires :price, type: Float requires :media_type, type: String requires :width, type: Float requires :height, type: Float requires :contact_person, type: String requires :adress, type: String requires :period, type: String optional :comments, type: String requires :region, type: String requires :postcode, type: String end end post do ::Use::Item::Create.run(declared(params)[:item]) end I have created a form in AngularJS, and services to push frontend data to my backend (It works well), but don't really know how to do that with image using AngularJS and Paperclip gem, I've installed a ngFileUpload, and library has started uploading my file but it ends with 500 Server Internal Error. Anybody has an idea to resolve my problem? |
Rake Task environment variable w/Command Line Arguments Posted: 04 Aug 2016 08:07 AM PDT So I was getting some "Uninitalized constants" on my rake task, and I did some googling and found that the environment variable needed to be loaded in. However im also using a command line argument and im not sure if the positioning is correct or what: desc "Wipes Specific User" task :clean_user => environment [:user] do |t, args| puts "Running clean_user for #{args[:user]}..." Core::Stuff.find(args[:user]).wipe_user end Without the environment variable somewhere I get complains about Core::Stuff being uninitialized, but Im trying to pass :user via CL. (This is just a sample rake task to make sure stuff works). Am I missing something? |
how to get data from 2 rails join tables Posted: 04 Aug 2016 07:51 AM PDT i have a join table between alarms and lists, and have a join table between lists and cars, i want to find the alarm to be notified when a certain car is added in a certain list, i tried to use alarm.list.cars but that's doesn't work any help please Thanks in advance |
Rubymine RoR project is empty/rails server wasn't found in project Posted: 04 Aug 2016 07:47 AM PDT When I create a Rails project in Rubymine it stops straight away, saying "Rails server wasn't found in project". I installed rails (it turns up in the SDK settings too) and I tried deleting .idea and restarting. I have done this before on another machine, but not sure what else to debug at this point - any suggestions? |
Render partial from Helper in Rails 4 Posted: 04 Aug 2016 07:45 AM PDT I have read a lot of guides but I can not understand why this my method does not work: module StudentsHelper def get_training_projects @training_projects_student = TrainingProject.where(student_id: @student.id) @training_projects_student.count end def get_training_courses @training_course_student = TrainingCourse.joins(:courses_students).where(courses_students: { student_id: @student.id }) @training_course_student.count end def storico_studente n = get_training_courses + get_training_projects i_projects = 0 i_courses = 0 until i_courses + i_projects < n if @training_course_student[i_courses].data_inizio < @training_projects_student[i_projects].data_inizio render partial: "training_course", collection:@training_course_student[i_cousers] i_courses += 1 else render partial: "training_project", collection: @training_course_student[i_projects] i_projects += 1 end end end end The "_training_project.html.erb" and "_training_course.html.erb" files are in the folder students. |
How to handle already enqueued jobs after number of args in related worker has been reduced? Posted: 04 Aug 2016 08:06 AM PDT Let's say I have a worker with some params: class Foo include Sidekiq::Worker sidekiq_options queue: :critical def perform(param1, param2, param3) ... end end It worked for some time and then I reduced number of worker's args: class Foo include Sidekiq::Worker sidekiq_options queue: :critical def perform(param1, param2) ... end end But there are some jobs with previous number of args in the queue still. What is the best way to handle such situations? |
Jquery dropdown list set Id automatically Posted: 04 Aug 2016 07:42 AM PDT index.html.haml I have a form which has a dropdown list which has several fields. I want a customer to choose the field which has to be displayed in a form.And the rest of the fields should be hidded from the form. .col-xs-12.table-responsive = form_for(@customer_detail) do |f| .field-list = f.label :field_list,"Choose the fields to be displayed", class: "col-sm-3 control-label text-right" = f.select :field_list, options_for_select(CustomerDetail::FIELD_LIST_CUSTOMER),{}, {prompt: "Field List", class: "checkbox_list_for_tax_org form-control form-width", "data-live-search": "true", multiple:"multiple"} %table.table.table-striped %thead %tr %th Customer Name %th Customer ID %th Address %th State %th Email %th Website %th Service Tax No %th Local Sales Tax No %th Residential Type %th Attention To %th City %th Pin Code %th Contact No %th Business Type %th PAN No %th Central Sales Tax No %th Business Center %th Opening Bal %th Currency Type %th Name %th Address %th State %th Contact No %th Pin Code %th Delivery Address %tbody %div{id: 'display_fields'} - @customer_details.each do |customer| %tr %td= customer.customer_name %td= customer.customer_id %td= customer.address %td= customer.state %td= customer.email %td= customer.website %td= customer.service_tax_reg_no %td= customer.local_sales_tax_reg_no %td= customer.residential_type %td= customer.attention_to %td= customer.city %td= customer.pin_code %td= customer.contact_no %td= customer.business_type %td= customer.pan_no %td= customer.central_sales_tax_no %td= customer.business_center %td= customer.opening_bal - if customer.goods_address.present? %td= customer.goods_address.name %td= customer.goods_address.contact_no %td= customer.goods_address.address %td= customer.goods_address.state %td= customer.goods_address.pin_code %td= customer.goods_address.delivery_address $('.field-list').on('click', function(){ if($(this).is('clicked', true)) { $('#display_fields').attr(true) } else { $('#display_fields').removeAttr(true) } The problem is I dont know how to set Id for each field. I need to display only the fields which has been selected in dropdown.can someone plz help me. thanks in advance!! |
How to skip a hash if the fields contain Encoding::UndefinedConversionError: U+00A0 from UTF-8 to US-ASCII Posted: 04 Aug 2016 07:34 AM PDT I am calling a remote service and the result is Encoding::UndefinedConversionError: U+00A0 from UTF-8 to US-ASCII. How can I skip such responses and go to the next iteration of the loop. Is there a way in which I can identify if a hash contains a field with such special characters. |
extending Module trough ApplicationRecord Rails 5 Posted: 04 Aug 2016 07:21 AM PDT I am trying to extend a module in the application_record.rb file in Rails 5.0. The module is located in the /lib folder: class ApplicationRecord < ActiveRecord::Base self.abstract_class = true extend UpdateLive extend UpdatePre end When trying to use a method in one of the Models I get the following error: NameError: uninitialized constant ApplicationRecord::UpdateLive I can't seem to figure out what I am doing wrong, or if I forgot a step? |
How to populate Rails app with existing mongo database? Posted: 04 Aug 2016 07:21 AM PDT I have a database "market" with collection "users". I want to create a Rails app and populate it with an existing data. So, I have a few questions: 1. Which gem better use? Mongoid or maybe mongo_mapper 2. What to write in config to indicate with which db to work? 3. How to bind User model with collection. I tried to write the following in mongoid.yml database: market but it didn't work. Please, describe me how to make it step by step. Thanks in advance. |
Fallback for Turbolinks 5.0 with jQuery ready() Posted: 04 Aug 2016 07:16 AM PDT What is the correct way to set up the Javascript that needs to run on page load when using Rails Turbolinks 5.0? The code needs to execute exactly once on every page load, even when the page is viewed in a browser where Turbolinks don't work. The following code does the job when Turbolinks do work: function setupPage() { // Setup code that cannot run more than once. } // Fires with every page request (full or triggered with Turbolinks) $(document).on('turbolinks:load', function(){ setupPage(); }); When the browser does not support Turbolinks I still have to run the set up code. i.e like so: // Fires only with full page reload - Intended as a fallback for when Turbolinks are not supported by the browser. $(document).ready(function(){ setupPage(); }); The problem is the above fallback solution causes the setupPage() function to run twice on the full page reload when Turbolinks are supported. What is the standard way of dealing with this issue? |
Rails - mongodb - root user Posted: 04 Aug 2016 07:01 AM PDT My goal is create own root user in mongodb who has access to any database, any collection and perform all actions as root. Below is my mongoid.yml file development: clients: default: database: mydb_development hosts: - localhost:27017 options: user: myrootuser password: 12345 options: raise_not_found_error: false I read the documentation and I've created new myrootuser use admin db.createUser({user: 'myrootuser', pwd: '12345', roles: ['root']}); It created the user successfully but with access to admin database only instead of to any database. Mongo::Auth::Unauthorized (User myrootuser is not authorized to access mydb_development.): On the other hand when I'd like to add new root user being in mydb_development use mydb_development db.createUser({user: 'myrootuser', pwd: '12345', roles: ['root']}); I can't create new user and I get error: Error: couldn't add user: No role named root@mydb_development : So the question is : How to add new user with root privileges and be able to use it through mongoid.yml ? |
Paperclip | ImageMagick - Unable to resize image with custom height Posted: 04 Aug 2016 07:55 AM PDT I am using Paperclip's custom styles to resize some images. The custom style is defined as so - has_attached_file :image_preview, :styles => lambda { |a| { :original => "#{a.instance.model.aspect_ratio_width.to_f/2.54*300}x#{a.instance.model.aspect_ratio_height.to_f/2.54*300}"} } When the output is seen, the image was resized the the width parameter but never the height parameter! In the logs as well, I see that only the width parameter was taking into consideration during the ImageMagick operation -- Command :: file -b --mime '/tmp/46711c9258f556a83aa382084f5014d120160804-14501-h9qo6j.png' Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/46711c9258f556a83aa382084f5014d120160804-14501-16cbj3b.png[0]' 2>/dev/null Command :: identify -format %m '/tmp/46711c9258f556a83aa382084f5014d120160804-14501-16cbj3b.png[0]' Command :: convert '/tmp/46711c9258f556a83aa382084f5014d120160804-14501-16cbj3b.png[0]' -auto-orient -resize "1110" '/tmp/caba5ed9a9c1d9623acb7738fd6b8dda20160804-14501-5sjqq1' [paperclip] saving /cases/image_previews/000/000/045/original/Goku-Blue.png How can I make this happen? |
DataTables sorting icons don't show up without minified CSS Posted: 04 Aug 2016 07:29 AM PDT I came across something that I thought was very strange while installing the dataTables plugin in my app. I am using ruby on rails 4.2. If i have only the minified or only the non-minified js and css jquery.dataTables files in my assets, the sorting icons do not load properly. I get a RoutingError (No route matches [GET] "/images/sort_desc.png") . I've seen other people discuss this error, but have not actually seen a good solution for it. If I change the path to retrieve the images inside jquery.dataTables.css or the min version of the file, I still get the same error. The path in the error message does not change! The strange thing, is if I use the min.css and regular js files, the sorting icons load properly! Recap: jquery.dataTables.min.css & jquery.dataTables.js : WORKS jquery.dataTables.css & jquery.dataTables.js : DOES NOT WORK jquery.dataTables.min.css & jquery.dataTables.min.js : DOES NOT WORK jquery.dataTables.css & jquery.dataTables.min.js : DOES NOT WORK I am putting these files inside vendor/assets/stylesheets , ../javascripts , ../images . What is going on here? |
rspec shows backtrace instead of test names Posted: 04 Aug 2016 06:42 AM PDT I've upgraded a Rails 4 app to Rails 5. The tests are running fine so far, but the output or spec is very tidy. It doesn't show anymore the test names but instead it shows me some kind of backtrace. So, what am I missing? Here's the project: https://github.com/polyvision/EasyRaceLapTimer/tree/racemanagement And here's an example output: finished race pilot reached max lap in competition mode /Users/ghostrifle/development/EasyRaceLapTimer/web/app/adapters/race_session_adapter.rb:248:in `track_lap_time_competition_mode' /Users/ghostrifle/development/EasyRaceLapTimer/web/app/adapters/race_session_adapter.rb:173:in `track_lap_time' /Users/ghostrifle/development/EasyRaceLapTimer/web/app/controllers/api/v1/lap_track_controller.rb:39:in `create' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/abstract_controller/base.rb:188:in `process_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_controller/metal/rendering.rb:30:in `process_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/abstract_controller/callbacks.rb:20:in `block in process_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:126:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:126:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:506:in `block (2 levels) in compile' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:455:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:455:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:101:in `__run_callbacks__' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:90:in `run_callbacks' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/abstract_controller/callbacks.rb:19:in `process_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_controller/metal/rescue.rb:20:in `process_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/notifications.rb:164:in `block in instrument' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/notifications.rb:164:in `instrument' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_controller/metal/instrumentation.rb:30:in `process_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_controller/metal/params_wrapper.rb:248:in `process_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-5.0.0/lib/active_record/railties/controller_runtime.rb:18:in `process_action' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/abstract_controller/base.rb:126:in `process' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionview-5.0.0/lib/action_view/rendering.rb:30:in `process' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_controller/metal.rb:190:in `dispatch' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_controller/metal.rb:262:in `dispatch' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/routing/route_set.rb:50:in `dispatch' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/routing/route_set.rb:32:in `serve' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/journey/router.rb:39:in `block in serve' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/journey/router.rb:26:in `each' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/journey/router.rb:26:in `serve' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/routing/route_set.rb:725:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/warden-1.2.6/lib/warden/manager.rb:35:in `block in call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/warden-1.2.6/lib/warden/manager.rb:34:in `catch' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/warden-1.2.6/lib/warden/manager.rb:34:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/etag.rb:25:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/conditional_get.rb:38:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/head.rb:12:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/session/abstract/id.rb:222:in `context' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/session/abstract/id.rb:216:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/cookies.rb:613:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/callbacks.rb:38:in `block in call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:97:in `__run_callbacks__' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:750:in `_run_call_callbacks' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:90:in `run_callbacks' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/callbacks.rb:36:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/remote_ip.rb:79:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/rack/logger.rb:36:in `call_app' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/rack/logger.rb:24:in `block in call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/tagged_logging.rb:70:in `block in tagged' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/tagged_logging.rb:26:in `tagged' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/tagged_logging.rb:70:in `tagged' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/rack/logger.rb:24:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/request_id.rb:24:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/method_override.rb:22:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/runtime.rb:22:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/executor.rb:12:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/static.rb:136:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/engine.rb:522:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rack-test-0.6.3/lib/rack/test.rb:124:in `request' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/testing/integration.rb:379:in `process' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/testing/integration.rb:296:in `process_with_kwargs' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/testing/integration.rb:46:in `post' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/testing/integration.rb:497:in `block (2 levels) in <module:Runner>' /Users/ghostrifle/development/EasyRaceLapTimer/web/spec/controllers/api/v1/lap_track_controller_spec.rb:517:in `block (3 levels) in <top (required)>' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:254:in `instance_exec' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:254:in `block in run' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:496:in `block in with_around_and_singleton_context_hooks' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:453:in `block in with_around_example_hooks' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/hooks.rb:471:in `block in run' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/hooks.rb:611:in `block in run_around_example_hooks_for' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:338:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:338:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-rails-3.5.1/lib/rspec/rails/example/controller_example_group.rb:191:in `block (2 levels) in <module:ControllerExampleGroup>' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:443:in `instance_exec' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:443:in `instance_exec' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/hooks.rb:382:in `execute_with' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/hooks.rb:613:in `block (2 levels) in run_around_example_hooks_for' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:338:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:338:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-rails-3.5.1/lib/rspec/rails/adapters.rb:127:in `block (2 levels) in <module:MinitestLifecycleAdapter>' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:443:in `instance_exec' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:443:in `instance_exec' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/hooks.rb:382:in `execute_with' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/hooks.rb:613:in `block (2 levels) in run_around_example_hooks_for' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:338:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:338:in `call' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/hooks.rb:614:in `run_around_example_hooks_for' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/hooks.rb:471:in `run' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:453:in `with_around_example_hooks' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:496:in `with_around_and_singleton_context_hooks' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example.rb:251:in `run' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example_group.rb:627:in `block in run_examples' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example_group.rb:623:in `map' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example_group.rb:623:in `run_examples' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example_group.rb:589:in `run' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example_group.rb:590:in `block in run' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example_group.rb:590:in `map' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/example_group.rb:590:in `run' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:113:in `block (3 levels) in run_specs' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:113:in `map' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:113:in `block (2 levels) in run_specs' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1836:in `with_suite_hooks' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:112:in `block in run_specs' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/reporter.rb:77:in `report' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:111:in `run_specs' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:87:in `run' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:71:in `run' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:45:in `invoke' /Users/ghostrifle/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.2/exe/rspec:4:in `<top (required)>' /Users/ghostrifle/.rbenv/versions/2.2.3/bin/rspec:23:in `load' /Users/ghostrifle/.rbenv/versions/2.2.3/bin/rspec:23:in `<main>' ....pilot: Pilot 1 pilot_num_tracked_laps: 1 max_laps_for_this_race: 5 RaceSessionEventAdapter::perform_for_competition_mode: triggering sound for la |
Axlsx ignores image.start_at Posted: 04 Aug 2016 06:56 AM PDT Just a small problem that i'm facing with axlsx_rails images. currently i have this: sheet.add_image(:image_src => img, :noSelect => false, :noMove => false) do |image| image.start_at 5, 5 image.end_at 15, 20 end and it seems to somehow ignore the image.start_at line. No matter what values i give it, the image starts from 0,0 (Cell A1) and stretches until the values specified in image.end_at . Does anyone know what could be causing this or how to get around it ? I need to simply put the image inside 3 merged cells. |
Storing ranges in array with JSONB Posted: 04 Aug 2016 06:40 AM PDT I've set the attribute data to JSONB type in the migration: t.jsonb :data, null: false, default: {} When trying to save the following: my_object.data = [1..3, 5..7] my_object.save The ranges are converted to strings: my_object.data => ["1..3", "5..7"] Is there any way to work with array of ranges with JSONB? |
prawn pdf displaying strange thing in rails Posted: 04 Aug 2016 06:10 AM PDT the link to pdf is working fine before!! but after I made a push, when i click the pdf url again, it gave me this I HAVE NO CLUE WHERE TO START DEBUGGING! |
rails: conditional erb not working as expected Posted: 04 Aug 2016 07:01 AM PDT I have a dropdown menu with a link to the user's profile page (UserProfile ). The user.user_profile is not created by default, so the link should only show if an associated user profile is present. I currently have: <% if profile_present? %> <%= link_to "My profile", user_profile_path(current_user.user_profile) %> <% end %> When the user profile is not present, this trows me a ActionController::UrlGenerationError . UPDATE My helper method: module ApplicationHelper def profile_present? current_user.user_profile.present? if user_signed_in? end end The goal is to only execute the code if the condition is met. Any suggestions? |
Google Authentication in Rails - "uninitialized constant GoogleAuthExample (NameError)" Posted: 04 Aug 2016 08:00 AM PDT I'm currently following this tutorial on integrating Google Authentication into Rails apps. I've only been learning Ruby / Rails for a few weeks (though have some other programming experience) and have encountered an error while following the tutorial - not sure if it's something really obvious that I'm misunderstanding. When I run try to start the server after following the instructions in the tutorial, I get: "Exiting /Users/adam/Code/rails_projects/quickcal/config/routes.rb:1:in `<top (required)>': uninitialized constant GoogleAuthExample (NameError)" Any ideas? EDIT: Still not working after changing GoogleAuthExample to the name of my app... config/routes.rb:1:in `<top (required)>': uninitialized constant QuickCal (NameError) EDIT: SOLVED Following on from previous edit, just had to change QuickCal to Quickcal - whoops! |
inappropriate inbound web traffic with strange query parameters: srcid, srctid, erid, trid, linkid, isbbox Posted: 04 Aug 2016 06:50 AM PDT I am seeing some strange inappropriate inbound traffic with query parameters not related to the operation of my website. I am terming these inbounds as "inappropriate" because they do not confirm to RFC-3986. Specifically, you will note they are missing the question mark (?) character which is required by the spec to separate the path from the query. As such, they crash on my back-end (which is Rails 4.1, but I don't think that's relevant to the question). Does anyone know where these might be coming from so I can report this error to the external site? (Obviously I cannot fix them on the server because Rails expects a properly formed URI) Note in the examples below I have changed my domain to example.com but the rest of the URL remains intact as reported by the server logs. https://www.example.com/c/heeleb&srcid=1787980&srctid=1&erid=119893333&trid=13158727-4e98-40db-91cf-743f68bd6124 https://www.example.com/c/heeleb&srcid=1787980&srctid=1&erid=119893333&trid=13158727-4e98-40db-91cf-743f68bd6124&linkid=22645711&isbbox=1 https://www.example.com/c/heeleb&srcid=1787980&srctid=1&erid=119893333&trid=13158727-4e98-40db-91cf-743f68bd6124 https://www.example.com/c/heeleb&srcid=1787980&srctid=1&erid=119890326&trid=d9f3e066-c82e-4e84-ba71-2b7fdc9a3b9b |
Spree commerce: post a specific taxon link Posted: 04 Aug 2016 05:51 AM PDT I'm a newbie about Rails and Spree commerce, so i'm so sorry if i ask a noob question. I'd like to post a specific taxon link, translated in two languages (i need dynamic link for that cause). How is it possible? Something like: if taxon permalink is "Bags" <%= link_to taxon permalink of bags %> Link: Bags (EN) or Borse (IT) Thank you |
Rails Associations Not working, user_id not showing in console Posted: 04 Aug 2016 07:04 AM PDT In console I get this error: peegin.user NameError: undefined local variable or method `peegin' for main:Object Did you mean? @peegin Also when i try to access Peegin in console it doesn't display user_id : Peegin => Peegin(id: integer, title: string, meaning: string, example: string, created_at: datetime, updated_at: datetime, permalink: string) 2.3.0 :039 > User Class class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :peegins end Peegin Class class Peegin < ActiveRecord::Base belongs_to :user before_create :generate_permalink def to_param permalink end private def generate_permalink pattern=self.title.parameterize duplicates = Peegin.where(permalink: pattern) if duplicates.present? self.permalink = "#{pattern}-#{duplicates.count+1}" else self.permalink = self.title.parameterize end end end Schema ActiveRecord::Schema.define(version: 20160804115242) do create_table "peegins", force: :cascade do |t| t.string "title" t.string "meaning" t.string "example" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "permalink" t.integer "user_id" end add_index "peegins", ["user_id"], name: "index_peegins_on_user_id", unique: true create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "name" end add_index "users", ["email"], name: "index_users_on_email", unique: true add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end |
Gem spree doesn't work in Rails 5 Posted: 04 Aug 2016 05:44 AM PDT Gem spree doesn't work in Rails 5 DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at C:/Users/Sergey/spree/config/application.rb:7) C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'spree'. (Bundler::GemRequireError) from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler.rb:99:in `require' from C:/Users/Sergey/spree/config/application.rb:7:in `<top (required)>' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:88:in `require' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:88:in `block in server' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:85:in `tap' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:85:in `server' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in `run_command!' from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>' I have added 'spree' gem in Gemfile. |
omniauth-facebook test with devise Posted: 04 Aug 2016 05:30 AM PDT I am starting with using omniauth with devise User model. Integration works well but a case is failing. This is related code from omniauth callback controller: class OmniauthCallbacksController < Devise::OmniauthCallbacksController before_action :find_user, only: [:facebook] def facebook process_omniauth_response('Facebook', request.env['omniauth.auth'], @user) end def failure redirect_to root_path, flash: { error: 'Authentication \ failed, please try again!' } end private def find_user @user = User.from_omniauth(request.env['omniauth.auth']) end def process_omniauth_response(provider, env_data, user) if user.persisted? sign_in_and_redirect user, event: :authentication set_flash_message(:notice, :success, kind: provider) if is_navigational_format? else session["devise.#{provider.downcase}_data"] = env_data redirect_to new_user_registration_url end end end And the User model methods: def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_create do |user| info = auth.info user.email = info.email user.remote_profile_picture_url = info.image user.name = info.name user.password = Devise.friendly_token[0, 20] end end def self.new_with_session(params, session) super.tap do |user| auth_data = session['devise.facebook_data'] || session['devise.twitter_data'] fill_with_omniauth_data(user, auth_data) if auth_data end end def self.fill_with_omniauth_data(user, auth_data) data_info = auth_data['info'] user.email = data_info['email'] if user.email.blank? user.name = data_info['name'] if user.name.blank? ... end So everything works fine i.e if a new user clicks on login by Facebook, after authentication by facebook he will come to signup page with pre-filled data but in case of this below case it is going to sign in page after omniauth callback action: context 'when facebook email doesn\'t exist in the system' do before(:each) do stub_env_for_omniauth get :facebook end it { response.should redirect_to new_user_registration_path } it 'should create authentication with facebook id' do authentication = User.where(provider: 'facebook', uid: '1234').first puts authentication.inspect authentication.should_not be_nil end end And the stub method: def stub_env_for_omniauth request.env['devise.mapping'] = Devise.mappings[:user] request.env['omniauth.auth'] = OmniAuth::AuthHash.new( provider: 'facebook', uid: '1234', info: { email: 'ghost@nobody.com', name: 'mock user' }, extra: { raw_info: { age: 23 } } ) end I got this message: Expected response to be a redirect to http://test.host/users/sign_up but was a redirect to http://test.host/users/sign_in From debugging I got that user object is a new , not persisted when I check it in the 'find_user' method of controller but in case of spec it is a persisted one. I would appreciate any help. Thanks |
Update rails from 4.2 to 5.0 on windows Posted: 04 Aug 2016 05:36 AM PDT I just installed rails using the awesome rails installer for windows. Unfortunately there is not yet the option available to use the installer for Rails 5, what is the easiest way to upgrade on Windows? I currently have ruby version 2.2.4 and rails 4.2 |
undefined method `model_name' for #<Hash:0x007efcfb0c19e0> Posted: 04 Aug 2016 05:26 AM PDT I using gem 'firebase' and getting data from firebase. I can create,show data but problem with update action . here is my code user.rb file require 'firebase' class User < ActiveRecord::Base FIREBASE = Firebase::Client.new("url" ,"secret") def self.all response = FIREBASE.get('users') response.body.present? ? response.body : {} end def self.find(id) FIREBASE.get("/users/#{id}").body end def self.update(id, data) response = FIREBASE.update("/users/#{id}", data) return response.success? end end and users_controller.rb file: class UsersController < ApplicationController respond_to :html, :json def edit @user = User.find("#{params[:id]}") end def update @user = User.find(params[:id]) User.update("#{@user[0]}", user_params) respond_with @user end private def user_params params.require(:user).permit(:name) end end and edit.html.erb file: <%= form_for @user do |f| %> <%= f.text_field :name %> <%= f.submit %> <% end %> here is my error logs: Started GET "/users/-KOKEM82melqy/edit" for 180.211.159.218 at 2016-08-04 12:19:58 +0000 Cannot render console from 180.211.159.218! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by UsersController#edit as HTML Parameters: {"id"=>"-KOKEM82melqy3"} Rendered users/edit.html.erb within layouts/application (5.2ms) Completed 500 Internal Server Error in 40ms (ActiveRecord: 0.0ms) ActionView::Template::Error (undefined method `model_name' for #<Hash:0x007efcfb7c6ab0>): 1: <h1>Editing user</h1> 2: <%= form_for @user do |f| %> 3: <div class="field"> 4: <%= f.label :name %><br> 5: <%= f.text_field :name %> app/views/users/edit.html.erb:2:in `_app_views_users_edit_html_erb__2046577153275023374_69812507750700' i tried a lot of times but noting work. any suggestion ? if u need more information about this, please let me know. Thanks in advance. |
TypeError no implicit conversion of PicUploader into String Posted: 04 Aug 2016 05:22 AM PDT I'm using axlsx-rails to generate excel sheets that contain the info that is in my User entity. the problem arises when i try to put an image in the excel sheet. I'm using carrierwave 0.11.2 and I've made sure that I have set it up correctly, I have the string column profile_pic that holds the image, I have the uploader PicUploader and it's mounted to User. the carrierwave implementation works fine, and the picture shows in the user's "show" page but when i try to follow the axlsx example to put the image in the sheet as such img = File.expand_path(@user.profile_pic, __FILE__) sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image| image.width=420 image.height=669 end I get the TypeError no implicit conversion of PicUploader into String Any idea what might be causing this ? |
Rails + Google Calendar API events not created Posted: 04 Aug 2016 06:06 AM PDT I created rails web app. When user make some actions, my app must create new event in my Google Calendar. For my task I choose server-to-server authorization. I wrote next ruby code: client = Google::APIClient.new({:application_name => "Rails calendar", :application_version => "1.0"}) keypath = Rails.root.join('config','google_secrets.p12').to_s key = Google::APIClient::PKCS12.load_key(keypath, "notasecret") # generate request body for authorization client.authorization = Signet::OAuth2::Client.new( :token_credential_uri => 'https://accounts.google.com/o/oauth2/token', :audience => 'https://accounts.google.com/o/oauth2/token', :scope => 'https://www.googleapis.com/auth/calendar', :issuer => '***', :signing_key => key).tap{ |auth| auth.fetch_access_token! } api_method = client.discovered_api('calendar','v3').events.insert @meeting_data = { guests: [{email: '***@gmail.com'}, {email: '***@gmail.com'}], start_time: "2016-08-10T19:00:00+03:00", end_time: "2016-08-10T20:00:00+03:00", topic: "Test meeting", messages_thread_id: 2 } event = { summary: @meeting_data[:topic], start: { dateTime: @meeting_data[:start_time], time_zone: 'Asia/Jerusalem' }, end: { dateTime: @meeting_data[:end_time], time_zone: 'Asia/Jerusalem' }, attendees: @meeting_data[:guests], visibility: 'private', reminders: { useDefault: true, } } result = client.execute(:api_method => api_method, :parameters => {calendarId: 'primary'}, :body => JSON.dump(event), :headers => {'Content-Type' => 'application/json'}) puts result.data.as_json But when i try to use that code and server return me result as JSON, if I go on url of "created" event, google show me message that event does not exist. {"kind"=>"calendar#event", "etag"=>"***", "id"=>"***", "status"=>"confirmed", "htmlLink"=>"https://www.google.com/calendar/event?eid=***", "created"=>"2016-08-04T11:54:46.000Z", "updated"=>"2016-08-04T11:54:46.327Z", "summary"=>"Test meeting", "creator"=>{"email"=>"***", "self"=>true}, "organizer"=>{"email"=>"***", "self"=>true}, "start"=>{"dateTime"=>"2016-08-10T16:00:00Z", "timeZone"=>"Asia/Jerusalem"}, "end"=>{"dateTime"=>"2016-08-10T17:00:00Z", "timeZone"=>"Asia/Jerusalem"}, "visibility"=>"private", "iCalUID"=>"***", "sequence"=>0, "attendees"=>[{"email"=>"***@gmail.com", "displayName"=>"***", "responseStatus"=>"needsAction"}, {"email"=>"***@gmail.com", "displayName"=>"***", "responseStatus"=>"needsAction"}], "reminders"=>{"useDefault"=>true}} |
Rails Concurrent record creation with unique column(s) Posted: 04 Aug 2016 05:02 AM PDT I have two background workers which will create new a record if not created or it will update record's attributes if already created based on the uniq_id . Code: entity = Entity.where(uniq_id: uniq_id).first_or_initialize entity.some_attribute = some_value entity.save! Consider both workers are en-queued with some jobs of same uniq_id = 1 and first time the entity was not created in the database. So, both jobs will initialize two different objects with same the uniq_id , and at certain point of time, one of the worker will create an entity in database with the uniq_id = 1 . Now the problem is, the second worker will try to create another record with the initialized entity object which has the same uniq_id . Since there exists an another record with same uniq_id , database validation will throw an exception and the worker stops the process and retries it from the first. On the second time, since there is record with same uniq_id , instead if initializing, it will take existing record and updates. Is there any way to make it work without a single retry? |
No comments:
Post a Comment