Identifying users in Rails Web push notifications Posted: 09 Nov 2016 08:29 AM PST I'm developing a Rails application, and I'd like to send web push notifications to specific users when certain actions happen, e.g: A user started tracking a timer, but the timer has been running for more than 6 hours. Then the app sends that user a web notification. I've been doing research and found this tutorial, the author implements push notifications for Rails, however there's no insight on how to identify the users. From what I understood, the users needs to subscribe from their browser to be able to get push notifications, however, considering each user can use the application from multiple browsers, how can I automatically subscribe/unsubscribe a user for notifications in all browsers they use the app from? |
How do I upgrade my activesupport gem? Posted: 09 Nov 2016 08:15 AM PST I'm on Mac Sierra. I was having trouble creating a new project in my workspace, so I decided to check my Rails version. I ran this command localhost:workspace davea$ rails --version /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:310:in `to_specs': Could not find 'activesupport' (= 5.0.0.1) - did find: [activesupport-4.2.5.1] (Gem::MissingSpecVersionError) Checked in 'GEM_PATH=/Users/davea/.rvm/gems/ruby-2.3.0:/Users/davea/.rvm/gems/ruby-2.3.0@global', execute `gem env` for more information from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:1439:in `block in activate_dependencies' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:1428:in `each' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:1428:in `activate_dependencies' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:1410:in `activate' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:68:in `block in gem' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:67:in `synchronize' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:67:in `gem' from /Users/davea/.rvm/gems/ruby-2.3.0/bin/rails:22:in `<main>' from /Users/davea/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval' from /Users/davea/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>' I don't know why I'm getting the above but it seems like I have a problem with ActiveSupport. How do I upgrade the version of ActiveSupport that I'm using? Edit: Here's the output of the suggestions … localhost:workspace davea$ bundle install Could not locate Gemfile or .bundle/ directory localhost:workspace davea$ bundle exec rails --version Could not locate Gemfile or .bundle/ directory |
route for nested model with simple_form Posted: 09 Nov 2016 08:07 AM PST I have a Proposal Model, which has_one Quote . I'm using simple_form to create both objects at the same time. The thing is, I want the quote to be a clone of another quote, that belongs to another model Brief . In my controller, this looks like that: def new @proposal = Proposal.new @brief = Brief.find(params[:brief_id]) @proposal.brief = @brief @invoice_quote_element = @brief.invoice_quote_element.deep_clone include: [ :expense_categories, { expense_categories: :expenses } ] end In my view, I add the form with <%= simple_form_for [@proposal.brief, @proposal, @invoice_quote_element] do |f| %> But this does not work, and I'm getting the following error: undefined method `brief_proposal_invoice_quote_elements_path' My routes seem clean to me: resources :proposals do resources :invoice_quote_element member do get 'edit_legal' patch 'update_legal' get 'quote' get 'view_quote' get 'download_quote' end end Now, if I remove the @invoice_quote_element from the simple_form <%= simple_form_for [@proposal.brief, @proposal] do |f| %> The form displays just fine, but I cannot submit it, because the create method raises a new error: Couldn't find InvoiceQuoteElement with ID=299 for Proposal with ID= |
ActiveModel::MissingAttributeError (can't write unknown attribute `order_id`) in production Posted: 09 Nov 2016 08:03 AM PST In development environment everything works fine but in production (when deployed to Heroku) it throws me MissingAttributeError. class Order < ApplicationRecord has_many :cart_items, dependent: :destroy end class CartItem < ApplicationRecord belongs_to :order, optional: true, foreign_key: "order_id" end create_table "cart_items", force: :cascade do |t| t.integer "item_id" t.integer "cart_id" t.integer "user_id" t.integer "order_id" end |
Wrong controller is active when using an external SQL table. Posted: 09 Nov 2016 07:42 AM PST I am working on a back-office app. The apps I am deploying have a model/table of user_messages. The user messages are used to display admin messages from a central app. The idea is that I can use that app to publish messages to the individual apps such as "System will be unavailable from noon to 1 on Friday". The individual apps use their own schema in the database. for example, the research library would be rl.user_messages etc. Since I will need to access multiple tables, I set it up so I can access external tables. production: adapter: sqlserver host: server1 port: 1435 database: web username: XX password: xXX schema_search_path: umc technical_libraries: adapter: sqlserver host: server1 port: 1435 database: XXXX username: XX password: XXXXXXXX schema_search_path: tl The model that lets me connect to the technical library as an external model is class TechnicalLibrary < ActiveRecord::Base self.abstract_class = true def self.table_name_prefix 'tl_' end establish_connection "technical_libraries" # TODO might want to name this to a generic end class UserMessage < TechnicalLibrary self.table_name = "tl.user_messages" # for this one, as opposed to the product development, we need to specify the schema. end My technical Libraries controller is class TechnicalLibrariesController < ApplicationController def index @user_messages= TechnicalLibrary::UserMessage.all end def show @technical_library = TechnicalLibrary::UserMessage.first # TODO HARDWIRED - end def new @technical_library = TechnicalLibrary::UserMessage.new end def edit @technical_library = TechnicalLibrary::UserMessage.find(params[:id]) end def create @technical_library = TechnicalLibrary::UserMessageRl.new(technical_library_params) respond_to do |format| if @technical_library.save format.html { redirect_to @technical_library, notice: 'Technical library was successfully created.' } format.json { render :show, status: :created, location: @technical_library } else format.html { render :new } format.json { render json: @technical_library.errors, status: :unprocessable_entity } end end end def update respond_to do |format| if @technical_library.update(technical_library_params) format.html { redirect_to @technical_library, notice: 'technical library was successfully updated.' } format.json { render :show, status: :ok, location: @technical_library } else format.html { render :edit } format.json { render json: @technical_library.errors, status: :unprocessable_entity } end end end def destroy end end private # Use callbacks to share common setup or constraints between actions. def set_technical_library @technical_library = TechnicalLibrary.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def technical_library_params params.require(:technical_library).permit(:message, :expires) end My technical Libraries form is <%= form_for(@technical_library) do |f| %> <% if @technical_library.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@technical_library.errors.count, "error") %> prohibited this technical_library from being saved:</h2> <ul> <% @technical_library.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :message %><br> <%= f.text_field :message %> </div> <div class="field"> <%= f.label :expires %><br> <%= f.datetime_select :expires %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> <hr> Controller <%= controller_name %> | <%= action_name %> <hr> The form looks as follows. The submit button seems to be wrong. it is pointing to another model. If I click on the submit button, I get an error message as follows. I suspect that the problem lies in inheriting from another model. NameError in UserMessagesController#show uninitialized constant TechnicalLibrary::UserMessageRl Rails.root: C:/Users/cmendla/RubymineProjects/user_message_console_3 Application Trace | Framework Trace | Full Trace app/controllers/user_messages_controller.rb:15:in `show' Request Parameters: {"id"=>"1"} I had a UserMessage model that I'm probably not going to use since I will connect to the individual application's tables. class UserMessage < ActiveRecord::Base end |
Rails: How to seperate jquery from html? Posted: 09 Nov 2016 08:05 AM PST Really simple question. I'm writing a plugin for Redmine in Ruby on Rails. I want to do this I have this in my form.html.rb: <table> <tr> <td >Specific operations/procedures</td> <td> <input type="checkbox" value="mfi_nam9" class="checkme"/>Other(please specify)<br/> <input type="text" name="mfi_nam9" disabled="true" > </td> </tr> <tr> <td >General principles/strategies</td> <td> <input type="checkbox" value="mfi_nam8" class="checkme"/>Other(please specify):<br/> <input type="text" name="mfi_nam8" disabled="true"> </td> </tr> </table> # compatibility for use as redmine plugin <% content_for :header_tags do %> <%= javascript_include_tag 'checkbox_enable', :plugin => 'students' %> <% end %> I have this in my "checkbox_enable.js" file: $(function() { $('.checkme').attr('checked', true); $('.checkme').click(function(){ if($('input[name='+ $(this).attr('value')+']').attr('disabled') == false){ $('input[name='+ $(this).attr('value')+']').attr('disabled', true); } else { $('input[name='+ $(this).attr('value')+']').attr('disabled', false); } }); } Look at my very first line of that file. I don't know if it's right. I don't really understand the difference between javascript and jquery that well. But the javascript has no impact on the html file. How do I make this work? EDIT: I just noticed that the fiddle only works for jquery 1.5. Or it seems that way. Does that mean there's a good chance of it just not working on a lot (most?) browsers? If so, why would anyone use jquery for anything? |
Rails. Undefined method `name' for ["Category1", 1]:Array Posted: 09 Nov 2016 08:12 AM PST I am still not very clear about loops, but this time its even more confusing. I have Product and Category models and relations between them :has_many and :belongs_to. In my apps navbar I have a dropdown to show categories: <% @categories.each do |cat| %> <li><%= link_to cat.name, cat %></li> <% end %> (I will move this loop to partial later) It was working fine, but now I noticed that if I try to use this link <%= link_to 'New Product', new_product_path %> it throws me that error of Undefined method 'name'... I can't even understand why this link triggers this peace of code: Products_controller.rb: def new @product = Product.new @categories = Category.all.map { |c| [ c.name, c.id ] } end shema.rb: create_table "categories", force: :cascade do |t| t.string "name" t.text "desc" t.datetime "created_at", null: false t.datetime "updated_at", null: false end |
Rails - render partial collection as not working Posted: 09 Nov 2016 07:31 AM PST I am trying to render a partial of a collection using a name different to that of the model: <%= render "current_campaigns", collection: @current_campaigns, as: :current_campaign %> The model is called Campaign but this is a subset of campaigns as defined in the controller action: def index @current_campaigns = Campaign.where(status: :approved) end In the partial: <%= current_campaign.question %> The resulting error: undefined local variable or method `current_campaign' for #<#<Class:0x007fad3d5e5500>:0x007fad451976a8> I was under the impression that as would make this work but apparently not. Any thoughts? |
Handling Custom Exceptions with exceptions_app Posted: 09 Nov 2016 07:26 AM PST I have set up my exception_app to point to routes.rb where I handle each type of exception. config/application.rg config.exceptions_app = self.routes config/routes.rb match "/404", to: "exceptions#exception_404", via: :all Appropriate error pages are then displayed in my exceptions_controller It seems that Rails doesn't offer an exception for a 410 so I would like to add a custom exception that is mapped by the exceptions_app to another action in my exceptions_controller . I have created a new gone_exception which I am raising in the appropriate place. However I don't know how to configure Rails so that this exception is mapped through the exceptions app to my new /410 path. How do I configure Rails so that my custom exception is mapped to my new /410 route: routes.rb match "/410", to: "exceptions#exception_410", via: :all |
Rails 4 + Wicked: Using params to route Posted: 09 Nov 2016 07:55 AM PST I have a bit of a complicated wizard and I'd like to route the user based on their entries to the form. I have listed the steps as follows: steps :weight_loss_history, :health_conditions, :cancer, :weight_mindset, :diabetes, :diet_information, :heart, :food_intake ...and my update and routing functions are as follows: def update @remote = current_remote params[:remote][:step] = step atts = Remote.fix_attributes(params[:remote]) @remote.attributes = atts # equal to large hash of params find_route(@remote) end def find_route(info) if info[:cancer] puts "cancer..." # I never see this in the console jump_to(:cancer) else render_wizard info end end Does anyone have a good implementation of using Wicked to route users based on their choices? |
How do I cure "uninitialized constant ActiveSupport::EventedFileUpdateChecker" when trying to generate a model? Posted: 09 Nov 2016 07:15 AM PST I'm on Mac Sierra. I'm using the following version or Rails davea$ rails --version Rails 4.2.7.1 I just created a project, but when I try and generate a model, I get the below error davea$ rails generate model GradingRubric description:text /Users/davea/Documents/workspace/sims/config/environments/development.rb:53:in `block in <top (required)>': uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError) from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/railtie.rb:210:in `instance_eval' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/railtie.rb:210:in `configure' from /Users/davea/Documents/workspace/sims/config/environments/development.rb:1:in `<top (required)>' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/engine.rb:598:in `block (2 levels) in <class:Engine>' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/engine.rb:597:in `each' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/engine.rb:597:in `block in <class:Engine>' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/initializable.rb:30:in `instance_exec' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/initializable.rb:30:in `run' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/initializable.rb:55:in `block in run_initializers' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/initializable.rb:44:in `each' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/initializable.rb:44:in `tsort_each_child' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:415:in `call' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `call' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each' from /Users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/initializable.rb:54:in `run_initializers' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/application.rb:352:in `initialize!' from /Users/davea/Documents/workspace/sims/config/environment.rb:5:in `<top (required)>' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/application.rb:328:in `require' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/application.rb:328:in `require_environment!' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:142:in `require_application_and_environment!' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:128:in `generate_or_destroy' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:50:in `generate' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from /Users/davea/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/commands.rb:17:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>' |
Apparent issue with dup and clone in Rails params Posted: 09 Nov 2016 07:51 AM PST I'm in a Rails controller. I try to take some params and change some of the datas to update a model, but I also want to keep the original params untouched. The logical way to go is to use clone or dup but whatever I try, it fails and changes the original hash. # Original product_params which is set as params.require(:product) {"name"=>"Product 2", "brand"=>"Brand 2", "desc"=>"Placeat a sunt eos incidunt temporibus.\r\n\r\nReprehenderit repudiandae amet quibusdam dolorem et. Itaque commodi at.", "hs_code"=>"12212121", "options_attributes"=> {"0"=>{"name"=>"hkjlVariation 4", "suboptions_attributes"=>{"0"=>{"name"=>"Chkjlhoice 0", "id"=>"582209026b710eded24ecd12"}}, "id"=>"582209026b710eded24ecd13"}, "1"=> {"name"=>"hhVhariation h5kkk", "suboptions_attributes"=>{"0"=>{"name"=>"Choice 0kh", "id"=>"582209026b710eded24ecd14"}, "1"=>{"name"=>"hkjChoice 1", "id"=>"582209026b710eded24ecd16"}, "2"=>{"name"=>"kkk"}}, "id"=>"582209026b710eded24ecd15"}, "2"=>{"name"=>"lh", "suboptions_attributes"=>{"0"=>{"name"=>"klhj"}}}}} # Method to change the `suboptions_attributes` to `nil` def product_params_without_suboptions copy = product_params.dup copy.tap do |product_param| product_param[:options_attributes].each do |key, option_attribute| unless option_attribute[:suboptions_attributes].nil? option_attribute[:suboptions_attributes] = nil end end end end # We define product_params def product_params params.require(:product).permit! end The result of product_params_without_suboptions is correct. It set all the option_attribute to nil but when I try to call params or product_params it also changed there. Why isn't dup working here ? |
undefined method `override_actionmailer_config=' for #<Spree::AppConfiguration:0x000000092faba8> (NoMethodError) Posted: 09 Nov 2016 07:03 AM PST I am currently upgrading my application from rails 3.2 to rails 4.2 also I am upgrading my Spree from 2.0 to 3.1 I am following this tutorial I have resolved other dependencies but I am still getting this error: undefined method `override_actionmailer_config=' for #< Spree::AppConfiguration:0x000000092faba8> (NoMethodError) Complete trace: $ rails s => Booting Thin => Rails 4.2.7.1 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server Exiting /home/deepak/.rvm/gems/ruby-2.3.1/gems/spree_core-3.1.1/app/models/spree/preferences/configuration.rb:66:in `method_missing': undefined method `override_actionmailer_config=' for #<Spree::AppConfiguration:0x000000092faba8> (NoMethodError) from /home/deepak/workspace/Project/config/initializers/spree.rb:12:in `block in <top (required)>' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/spree_core-3.1.1/lib/spree/core.rb:60:in `config' from /home/deepak/workspace/Project/config/initializers/spree.rb:8:in `<top (required)>' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/zeus-0.15.10/lib/zeus/load_tracking.rb:76:in `load' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/zeus-0.15.10/lib/zeus/load_tracking.rb:76:in `load' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/zeus-0.15.10/lib/zeus/load_tracking.rb:68:in `load' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `block in load' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:268:in `load' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/engine.rb:652:in `block in load_config_initializer' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/notifications.rb:166:in `instrument' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/engine.rb:651:in `load_config_initializer' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/engine.rb:615:in `each' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/engine.rb:615:in `block in <class:Engine>' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/initializable.rb:30:in `instance_exec' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/initializable.rb:30:in `run' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/initializable.rb:55:in `block in run_initializers' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/initializable.rb:44:in `each' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/initializable.rb:44:in `tsort_each_child' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `call' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each' from /home/deepak/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/initializable.rb:54:in `run_initializers' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/application.rb:352:in `initialize!' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/railtie.rb:194:in `public_send' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/railtie.rb:194:in `method_missing' from /home/deepak/workspace/Project/config/environment.rb:5:in `<top (required)>' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `block in require' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require' from /home/deepak/workspace/Project/config.ru:12:in `block in <main>' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize' from /home/deepak/workspace/Project/config.ru:in `new' from /home/deepak/workspace/Project/config.ru:in `<main>' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/server.rb:208:in `app' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/server.rb:61:in `app' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/server.rb:139:in `log_to_stdout' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/server.rb:78:in `start' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:80:in `block in server' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:75:in `tap' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:75:in `server' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from /home/deepak/.rvm/gems/ruby-2.3.1/gems/railties-4.2.7.1/lib/rails/commands.rb:17:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>' I have the following in config/initializers/spree.rb Spree.config do |config| # Example: # Uncomment to override the default site name. # config.site_name = "Spree Demo Site" config.override_actionmailer_config = false config.address_requires_state = true config.auto_capture = true config.always_include_confirm_step = true config.track_inventory_levels = false config.allow_ssl_in_staging = false config.allow_ssl_in_production = true config.mails_from = 'no-reply@something.com' config.default_country_id = ' ' end Thanks. |
How to make a FactoryGirl.create affect another record's attribute? Posted: 09 Nov 2016 06:59 AM PST In a webshop application normally after a booking of a product the bookings_controller create action does an order.save which in turn activates the necessary before_save method order.sum_of_all_bookings . When building a RSpec test for an admin viewing a list of orders, making a booking doesn't change the total of an order. The indexing does work in the browser. require 'rails_helper' RSpec.feature 'Admin can oversee orders' do let(:admin) { FactoryGirl.create(:user, :admin) } let(:customer) { FactoryGirl.create( :user ) } let!(:order_1) { FactoryGirl.create( :order, customer: customer ) } let!(:booking_1) { FactoryGirl.create( :booking, product_name: 'Honingpot', product_quantity: 1, product_price: '5,00', order: order_1 ) } let!(:order_2) { FactoryGirl.create( :order, customer: customer ) } let!(:booking_2) { FactoryGirl.create( :booking, product_name: 'Streekpakket', product_quantity: 2, product_price: '10,00', order: order_2 ) } before do order_1.sum_all_bookings order_2.sum_all_bookings login_as(admin) visit orders_path end scenario 'with success' do within('table#paid') do expect(page).to have_content '5,00' expect(page).to have_content '10,00' end end end Before block doesn't work. Neither does the factory girl after create: FactoryGirl.define do factory :booking do product_name 'Honingpot' product_quantity '1' product_price '3,99' order after(:create) { |booking| booking.order.save } end end How to make the order sum the bookings? Or more generally: How to make a FactoryGirl.create affect another record's attribute? |
rails admin edit fields localized Posted: 09 Nov 2016 06:58 AM PST How to localized edit fields in rails_admin i try config.model 'Draft' do edit do field :pick do label 'Значение' end end it work fine but it will take a very long time how to add custom field name builder for all feilds like this config.models do edit do fields do label "#{I18n.t(self.abstract_model.model_name.underscore)}" end end end |
How to add google maps to active admin? Posted: 09 Nov 2016 06:51 AM PST I am using active-admin in my rails app and want to plot the (lat, lot) on a google maps. Can someone please guide me how to go about it. Here is my booking_geo_locations.rb file ActiveAdmin.register BookingGeoLocation do show do attributes_table do row :id row :user_id row :date_pickup row :location_pickup row :date_dropoff row :location_dropoff row :location_pickup_latitude row :location_dropoff_latitude row :driver_price end end |
Post multiple fields (add/remove) Posted: 09 Nov 2016 06:48 AM PST How is the best way to POST multiple fields and insert/update in database using Ruby on Rails? For example, with Javascript I'll create a field and user can add more fields. When click the save button, how to proceed? Dog #1 name: Foo Dog #2 name: Puppy [remove] Dog #3 name: Rex [remove] [ADD DOG] [Save] In PHP I can count the fields. My question is about Ruby on Rails, I don't know if it have a best way. |
Rails server exiting immediately after starting <Undefined method> Posted: 09 Nov 2016 07:00 AM PST I have a strange issue. I just configured a rails project on a remote server. But immediately after I run 'rails server' command I get this error: [pediatric-nutri]# rails server => Booting WEBrick => Rails 4.1.16 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option) => Ctrl-C to shutdown server Exiting /home/lookwhat/rails_apps/pediatric-nutri/app/controllers/application_controller.rb:5:in `<class:ApplicationController>': undefined method `decent_configuration' for ApplicationController:Class (NoMethodError) from /home/lookwhat/rails_apps/pediatric-nutri/app/controllers/application_controller.rb:1:in `<top (required)>' from /usr/local/rvm/gems/ruby-2.3.1/gems/activesupport-4.1.16/lib/active_support/dependencies.rb:443:in `load' |
Rails server not starting Posted: 09 Nov 2016 08:18 AM PST `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError) I can confirm that this is a not a port issue. It happened after I changed by /etc/hosts file to use my custom domain name pointing to 127.0.0.1 but after I changed that rails server is not starting in any port. The command I am using to star: rvmsudo rails s -p 80 Here is how my etc/hosts file look like ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 platform.adwyze.com 255.255.255.255 broadcasthost ::1 platform.adwyze.com |
Rails acts as taggable on filter multiple tags Posted: 09 Nov 2016 06:25 AM PST From this question filter multiple tags I'm trying to understand how can I filter through my videos with multiple tags. Currently I'm being able to filter through them with single tag. My controller : if params[:tags] @videos = Video.tagged_with(params[:tags]) else @videos = Video.categorize(params[:id]).limit(4) end My routes :get 'categories/*tags', to: 'categories#show', as: :tag What I need is when I click on one tag, it shows me all videos that are tagged with that tag, and when I click on another tag after that it further filters through. How can I do that? Thanks! |
Unable to embed google plus posts Posted: 09 Nov 2016 06:05 AM PST I am trying to embed google plus posts in my application. I have loaded platform.js file in header <script> window.___gcfg = { lang: 'en-US', parsetags: 'onload' }; </script> <script src="https://apis.google.com/js/platform.js" async defer> </script> <script> function renderWidget() { gapi.post.render("widget-div", {'href' : 'https://plus.google.com/109813896768294978296/posts/hdbPtrsqMXQ'} ); } </script> In html page <a href="#" onClick="renderWidget();">Render the embedded post</a> <div id="widget-div"></div> When I clicked on the link, it shows nothing. Is there anything to be added. Here is the reference i followed https://developers.google.com/+/web/embedded-post |
Figaro/Rails 5 - uninitialized constant Pusher (NameError) Posted: 09 Nov 2016 06:04 AM PST I am trying to use Figaro to manage my environment variables and hide my SendGrid username and password. I have everything set up (see below), and when I try to start the rails server, I get the below exception. I am using rails 5 and rbenv to manage my dev environment if that helps. Any clues? $ rails s from /Users/gangelo/dev/rails/api.mohojo-werks/config/initializers/pusher.rb:1:in <top (required)>': uninitialized constant Pusher (NameError) from /Users/gangelo/dev/rails/api.mohojo-werks/vendor/bundle/gems/railties-5.0.0.1/lib/rails/engine.rb:648:inblock in load_config_initializer' from /Users/gangelo/dev/rails/api.mohojo-werks/vendor/bundle/gems/activesupport-5.0.0.1/lib/active_support/notifications.rb:166:in `instrument' etc... Gemfile gem 'figaro', '~> 1.1', '>= 1.1.1' config/application.yml pusher_sendgrid_username: xxxxx@heroku.com"" pusher_sendgrid_password: "xxxxx" config/initializers/pusher.rb Pusher.SENDGRID_USERNAME = ENV["pusher_sendgrid_username"] Pusher.SENDGRID_PASSWORD = ENV["pusher_sendgrid_password"] config/initializers/figaro.rb Figaro.require_keys("pusher_sendgrid_username", "pusher_sendgrid_password") |
Sequel class table inheritance Posted: 09 Nov 2016 07:21 AM PST I am hoping to start a project using Multiple/Class table inheritance in Rails. To do this i am planning to use Sequel instead of ActiveRecord. The Docs can be found here - Sequel - class table inheritance I have the Plugin working to an extent, I can call child.first and it will give me the first of the child classes, which is not the first of the parent class, and it includes the data from the child table. The problem is going the other way... So if i load a db row via the parent class, which happens to be a child2 class p = Parent.first <Parent @values = {kind = "Child2"}> and then try to get the child data by using the refresh command listed in the docs it SHOULD give me p.refresh <Parent @values = {kind = "Child2", child2data = "data from child 2 table"}> but it doesnt, it just returns the unaltered parent I have included a model map in my parent class plugin :class_table_inheritance,:key=>"kind", :model_map=>{"Child1"=>:Child1,"Child2"=>:Child2} And i have played about with different values and other nonsense it to try and get it to work, but no success. What i ideally want is to be able to find the parent and call a method to instance the child class so p = Parent.first c = p.child c <Child2 @values = {kind: "Child2", Child2data: "data from child2 table"> I feel like i can probably hack/add a method to my parent class to do this but it just feels quite simple at this point that i shouldnt have to, also the fact that the refresh method doesnt work worries me and id like that to be resolved Any one have an answer? ty for reading p.s. i am using rails 5, the rails-sequel gem, and am working in a project that is more or less blank, i just want to have a decent CTI setup because to me it seems so much more elegant than Polymorphic associations. |
Rails 5 - iterate until field matches regex Posted: 09 Nov 2016 08:14 AM PST In my app that I am building to learn Rails and Ruby, I have below iteration/loop which is not functioning as it should. What am I trying to achieve? I am trying to find the business partner (within only the active once (uses a scope)) where the value of the field business_partner.bank_account is contained in the field self_extracted_data and then set the business partner found as self.sender (self here is a Document ). So once a match is found, I want to end the loop. A case exists where no match is found and sender = nil so a user needs to set it manually. What happens now, is that on which ever record of the object I save (it is called as a callback before_save), it uses the last identified business partner as sender and the method does not execute again. Current code: def set_sender BusinessPartner.active.where.not(:receiver_id).each do |business_partner| bp_bank_account = business_partner.bank_account.gsub(/\s+/, '') rgx = /(?<!\w)(#{Regexp.escape(bp_bank_account)})?(?!\w)/ # need to fix the RGX if self.extracted_data.gsub(/\s+/, '') =~ rgx self.sender = business_partner else self.sender = nil end end end Thanks for helping my understand how to do this kind of case. p.s. have the pickaxe book here yet this is so much that some help / guidance would be great. The regex works. |
Any rails server doesn't start Posted: 09 Nov 2016 05:37 AM PST Getting the same error every time when trying to start ANY project on rails 4 or 5 using ruby 2.2.5 and 2.3.1 even on the fresh projects. Tried to reinstall rbenv but didn't help. Anybody got a solution? fedyay@fedyay-note:~/shit$ rails s => Booting WEBrick => Rails 4.2.3 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server Exiting /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/psych.rb:370:in `parse': (<unknown>): did not find expected alphabetic or numeric character while scanning an alias at line 22 column 20 (Psych::SyntaxError) from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/psych.rb:370:in `parse_stream' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/psych.rb:318:in `parse' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/psych.rb:245:in `load' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/application.rb:391:in `secrets' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/application.rb:178:in `key_generator' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/application.rb:206:in `message_verifier' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/globalid-0.3.7/lib/global_id/railtie.rb:25:in `block (2 levels) in <class:Railtie>' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:36:in `call' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `each' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/application/finisher.rb:62:in `block in <module:Finisher>' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `instance_exec' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/initializable.rb:30:in `run' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/initializable.rb:55:in `block in run_initializers' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/tsort.rb:345:in `each' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/tsort.rb:345:in `call' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/initializable.rb:54:in `run_initializers' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/application.rb:352:in `initialize!' from /home/fedyay/shit/config/environment.rb:5:in `<top (required)>' from /home/fedyay/shit/config.ru:3:in `require' from /home/fedyay/shit/config.ru:3:in `block in <main>' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize' from /home/fedyay/shit/config.ru:in `new' from /home/fedyay/shit/config.ru:in `<main>' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/server.rb:61:in `app' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/server.rb:139:in `log_to_stdout' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/server.rb:78:in `start' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:80:in `block in server' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `tap' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `server' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>' from /home/fedyay/shit/bin/rails:9:in `require' from /home/fedyay/shit/bin/rails:9:in `<top (required)>' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `load' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `call' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/spring-2.0.0/lib/spring/client/command.rb:7:in `call' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/spring-2.0.0/lib/spring/client.rb:30:in `run' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/spring-2.0.0/bin/spring:49:in `<top (required)>' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `load' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `<top (required)>' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require' from /home/fedyay/.rbenv/versions/2.2.5/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require' from /home/fedyay/shit/bin/spring:14:in `<top (required)>' from bin/rails:3:in `load' from bin/rails:3:in `<main>' |
why do I get a hash instead of an array when using nested attributes? Posted: 09 Nov 2016 06:26 AM PST I'm using nested attributes in may rails project but when I submit a form I get the _attributes as a hash of hashes not an array of hashes like it's said in the documentation, which means rails can't get the params for the new object. {"utf8"=>"✓", "authenticity_token"=>"oLy4lJyXBgKiUI+TlQgEGIRNLeNOG5WqiHLqYNiZYe1JXC7+/j02ZDsBAnVZCAgeUJw6B5iTXxkzV1XzUIDn+w==", "form"=>{"title"=>"test 3", "questions_attributes"=>{"0"=>{"question_text"=>"hello what?"}}}, "commit"=>"Create Form"} like in the code above :questions_attributes should have been an array not a hash with an element called '0' the form code: = form_for(setup_form(@form)) do |f| = error_messages_for(f.object) = f.label(:title, 'Title') = f.text_field(:title) = f.fields_for(:questions) do |q| = q.label(:question_text, 'Question') = q.text_field(:question_text) = f.submit "Create Form", :class => "btn btn-lg btn-primary" |
Connect Rails to CockroachDB Posted: 09 Nov 2016 07:38 AM PST CockroachDB is a very interesting distributed SQL db, which exposes PostgreSQL wire protocol. So I tried to connect a new Rails project to CockroachDB using the classic pg gem. Unfortunately, a simple rails db:create gave: /home/fengye87/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671: warning: Failed to set the default_internal encoding to UTF8: 'ERROR: unknown variable: "CLIENT_ENCODING" ' invalid encoding name: unicode So I guess it indicates that CockroachDB doesn't support CLIENT_ENCODING variable. The question is: is it possible to bypass setting these variables in pg? Does anyone managed to connect Rails to CockroachDB ever? Thanks! |
For a given period, getting the smallest list of dates, using jokers Posted: 09 Nov 2016 04:06 AM PST I use Elasticsearch where I have one index per day, and I want my Ruby on Rails application to query documents in a given period by specifying the smallest and most precise list of indices. I can't find the code to get that list of indices. Let me explain it: Consider a date formatted in YYYY-MM-DD . You can use the joker * at the end of the date string. E.g. 2016-07-2* describes all the dates from 2016-07-20 to 2016-07-29 . Now, consider a period represented by a start date and an end date. The code must return the smallest possible array of dates representing the period. Let's use an example. For the following period: - start date:
2014-11-29 - end date:
2016-10-13 The code must return an array containing the following strings: 2014-11-29 2014-11-30 2014-12-* 2015-* 2016-0* 2016-10-0* 2016-10-10 2016-10-11 2016-10-12 2016-10-13 It's better (but I'll still take a unoptimized code rather than nothing) if: - The code returns the most precise list of dates (i.e. doesn't return dates with a joker that describes a period starting before the start date, or ending after the end date)
- The code returns the smallest list possible (i.e.
["2016-09-*"] is better than ["2016-09-0*", "2016-09-1*", "2016-09-2*", "2016-09-30"] Any idea? |
rails server with PG:ConnectionBad error on Windows 7 Posted: 09 Nov 2016 03:52 AM PST When I run rails server I get the following: => Booting Puma => Rails 5.0.0.1 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options Please add the following to your Gemfile to avoid polling for changes: gem 'wdm', '>= 0.1.0' if Gem.win_platform? Please add the following to your Gemfile to avoid polling for changes: gem 'wdm', '>= 0.1.0' if Gem.win_platform? *** SIGUSR2 not implemented, signal based restart unavailable! *** SIGUSR1 not implemented, signal based restart unavailable! *** SIGHUP not implemented, signal based logs reopening unavailable! Puma starting in single mode... * Version 3.6.0 (ruby 2.3.1-p112), codename: Sleepy Sunday Serenity * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://localhost:3000 Use Ctrl-C to stop When I boot up a browser and navigate to localhost:3000 I get the following error rendered in the browser: Puma caught this error: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? (PG::ConnectionBad) C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `initialize' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `new' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `connect' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:217:in `initialize' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `new' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:721:in `new_connection' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:765:in `checkout_new_connection' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:744:in `try_to_checkout_new_connection' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:705:in `acquire_connection' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:501:in `checkout' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:in `connection' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:875:in `retrieve_connection' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_handling.rb:128:in `retrieve_connection' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_handling.rb:91:in `connection' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/query_cache.rb:47:in `block in install_executor_hooks' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:396:in `instance_exec' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:396:in `block in make_lambda' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:169:in `block (2 levels) in halting' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:547:in `block (2 levels) in default_terminator' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:546:in `catch' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:546:in `block in default_terminator' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:170:in `block in halting' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:454:in `block in call' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:454:in `each' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:454:in `call' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:101:in `__run_callbacks__' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:750:in `_run_complete_callbacks' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:90:in `run_callbacks' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/execution_wrapper.rb:107:in `complete!' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/execution_wrapper.rb:64:in `ensure in block in run!' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/execution_wrapper.rb:64:in `block in run!' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/execution_wrapper.rb:58:in `tap' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/execution_wrapper.rb:58:in `run!' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/executor.rb:10:in `call' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/static.rb:136:in `call' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in `call' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:522:in `call' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/configuration.rb:225:in `call' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/server.rb:578:in `handle_request' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/server.rb:415:in `process_client' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/server.rb:275:in `block in run' C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/puma-3.6.0/lib/puma/thread_pool.rb:116:in `block in spawn_thread' I did look at http://stackoverflow.com/a/21420719/1013849 but I cannot work out with my PID file is on a Windows 7 machine. How do I get this up and running? |
Rspec: Capybara select not working Posted: 09 Nov 2016 05:38 AM PST I am using JS enabled Capybara with selenium-webdriver for my feature test. I would like to select a brand from select box And here is my HTML <select id="campaign_brand_id" name="campaign[brand_id]" class="form-control"> <option value="">Choose a Brand</option> <option value="1">Brand1</option> <option value="2">Brand2</option> </select> Here is my test code before(:each) do @brand = FactoryGirl.create(:brand, name: 'Brand1', company: member.company) end scenario 'Create a new campaign - with minimum valid data', js: true do visit new_brands_campaign_url(host: "skreem.dev", port: Capybara.current_session.server.port) select (@brand.name), from: 'campaign_brand_id' click_button 'Create Campaign' end I have tried the following too... 1. select (@brand.name), from: 'campaign[brand_id]' 2. select (@brand.id), from: 'campaign_brand_id' 3. find('#campaign_brand_id').find(:xpath, "option[#{@brand.id}]").select_option 4. within '#campaign_brand_id' do find("option[value='1']").click end Other capybara commands like fill_in choose click_button are working... I am using collection_select in the view... Is that causing this problem? |
I am facing following issue
ReplyDeleteExiting
/usr/lib/ruby/vendor_ruby/rails/commands/server.rb:142:in `log_to_stdout': undefined method `formatter' for nil:NilClass (NoMethodError)
Any body help me regarding this issue