Wednesday, June 15, 2016

How to tell if bundle install is doing anything | Fixed issues

How to tell if bundle install is doing anything | Fixed issues


How to tell if bundle install is doing anything

Posted: 15 Jun 2016 07:36 AM PDT

I have created a vagrant instance from hashicorp/precise64 and once I logged in via putty changed to vagrant directory I ran

bundle install --verbose  

however the only output I have received is...

Fetching source index for https://rubygems.org  

My gemfile has approximately 150 gems and my gemfile.lock has over 500 lines. There has been no other output for half an hour and I was wondering at what point should I accept that something is wrong. I assumed with verbose specified there would be some output but nothing has appeared. Any help would be appreciated as I'm not sure if I'm just wasting my time.

Using Grape API with rails, deploy error on Heroku

Posted: 15 Jun 2016 07:30 AM PDT

I want to use Grape API and swagger on my project, and it worked fine on localhost. Beside, it didn't show sth weird when I deployed.

It just keeping showing this enter image description here Here is heroku logs

2016-06-15T13:52:34.591071+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'  2016-06-15T13:52:34.591085+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'  2016-06-15T13:52:34.591057+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'  2016-06-15T13:52:34.591133+00:00 app[web.1]:    from bin/rails:9:in `require'  2016-06-15T13:52:34.591147+00:00 app[web.1]:    from bin/rails:9:in `<main>'  2016-06-15T13:52:34.591118+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'  2016-06-15T13:52:35.789410+00:00 heroku[web.1]: Process exited with status 1  2016-06-15T13:52:35.986144+00:00 heroku[web.1]: State changed from starting to crashed  2016-06-15T13:52:47.291220+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=grape-pratice.herokuapp.com request_id=068008a8-0cab-4afc-9450-dc9e6bda0749 fwd="27.246.159.134" dyno= connect= service= status=503 bytes=  2016-06-15T13:52:49.338698+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=grape-pratice.herokuapp.com request_id=092b4295-e1c5-4248-b2e1-63c4e049d199 fwd="27.246.159.134" dyno= connect= service= status=503 bytes=  2016-06-15T13:53:27.047039+00:00 heroku[api]: Starting process with command `bundle exec rake db:create` by fifiteen82726@gmail.com  2016-06-15T13:53:29.895701+00:00 heroku[run.8765]: Awaiting client  2016-06-15T13:53:29.919402+00:00 heroku[run.8765]: Starting process with command `bundle exec rake db:create`  2016-06-15T13:53:30.181642+00:00 heroku[run.8765]: State changed from starting to up  2016-06-15T13:53:34.276935+00:00 heroku[run.8765]: Process exited with status 0  2016-06-15T13:53:34.314610+00:00 heroku[run.8765]: State changed from up to complete  2016-06-15T13:54:14.464093+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by fifiteen82726@gmail.com  2016-06-15T13:54:17.897130+00:00 heroku[run.4227]: Awaiting client  2016-06-15T13:54:17.921335+00:00 heroku[run.4227]: Starting process with command `bundle exec rake db:migrate`  2016-06-15T13:54:17.988883+00:00 heroku[run.4227]: State changed from starting to up  2016-06-15T13:54:23.699925+00:00 heroku[run.4227]: Process exited with status 0  2016-06-15T13:54:23.712160+00:00 heroku[run.4227]: State changed from up to complete  2016-06-15T13:54:36.588866+00:00 heroku[api]: Starting process with command `bundle exec rake db:seed` by fifiteen82726@gmail.com  2016-06-15T13:54:39.413129+00:00 heroku[run.6722]: Awaiting client  2016-06-15T13:54:39.430432+00:00 heroku[run.6722]: Starting process with command `bundle exec rake db:seed`  2016-06-15T13:54:39.654857+00:00 heroku[run.6722]: State changed from starting to up  2016-06-15T13:54:43.381225+00:00 heroku[run.6722]: Process exited with status 1  2016-06-15T13:54:43.390875+00:00 heroku[run.6722]: State changed from up to complete  2016-06-15T13:58:58.096288+00:00 heroku[slug-compiler]: Slug compilation started  2016-06-15T13:58:58.096296+00:00 heroku[slug-compiler]: Slug compilation finished  2016-06-15T13:58:58.117229+00:00 heroku[web.1]: State changed from crashed to starting  2016-06-15T13:58:57.901199+00:00 heroku[api]: Deploy e0325b7 by fifiteen82726@gmail.com  2016-06-15T13:58:57.901307+00:00 heroku[api]: Release v6 created by fifiteen82726@gmail.com  2016-06-15T13:59:00.604703+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 29411 -e production`  2016-06-15T13:59:04.816804+00:00 app[web.1]: => Booting WEBrick  2016-06-15T13:59:04.816822+00:00 app[web.1]: => Rails 4.2.5 application starting in production on http://0.0.0.0:29411  2016-06-15T13:59:04.816833+00:00 app[web.1]: => Run `rails server -h` for more startup options  2016-06-15T13:59:04.816834+00:00 app[web.1]: => Ctrl-C to shutdown server  2016-06-15T13:59:04.816880+00:00 app[web.1]: Exiting  2016-06-15T13:59:04.816983+00:00 app[web.1]: /app/app/api/root.rb:4:in `<class:Root>': uninitialized constant API::V1 (NameError)  2016-06-15T13:59:04.817007+00:00 app[web.1]:    from /app/app/api/root.rb:2:in `<module:API>'  2016-06-15T13:59:04.817021+00:00 app[web.1]:    from /app/app/api/root.rb:1:in `<top (required)>'  2016-06-15T13:59:04.817168+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:469:in `each'  2016-06-15T13:59:04.817117+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:471:in `each'  2016-06-15T13:59:04.817191+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:346:in `eager_load!'  2016-06-15T13:59:04.817041+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!'  2016-06-15T13:59:04.817154+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:471:in `block in eager_load!'  2016-06-15T13:59:04.817262+00:00 app[web.1]:    from /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'  2016-06-15T13:59:04.817275+00:00 app[web.1]:    from /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'  2016-06-15T13:59:04.817180+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/engine.rb:469:in `eager_load!'  2016-06-15T13:59:04.817251+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'  2016-06-15T13:59:04.817202+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application/finisher.rb:56:in `each'  2016-06-15T13:59:04.817214+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'  2016-06-15T13:59:04.817226+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'  2016-06-15T13:59:04.817238+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'  2016-06-15T13:59:04.817287+00:00 app[web.1]:    from /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'  2016-06-15T13:59:04.817381+00:00 app[web.1]:    from /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'  2016-06-15T13:59:04.817408+00:00 app[web.1]:    from /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'  2016-06-15T13:59:04.817420+00:00 app[web.1]:    from /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'  2016-06-15T13:59:04.817432+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'  2016-06-15T13:59:04.817445+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'  2016-06-15T13:59:04.817457+00:00 app[web.1]:    from /app/config/environment.rb:5:in `<top (required)>'  2016-06-15T13:59:04.817339+00:00 app[web.1]:    from /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/tsort.rb:345:in `call'  2016-06-15T13:59:04.817506+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'  2016-06-15T13:59:04.817520+00:00 app[web.1]:    from /app/config.ru:in `new'  2016-06-15T13:59:04.817532+00:00 app[web.1]:    from /app/config.ru:in `<main>'  2016-06-15T13:59:04.817544+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'  2016-06-15T13:59:04.817469+00:00 app[web.1]:    from /app/config.ru:3:in `require'  2016-06-15T13:59:04.817482+00:00 app[web.1]:    from /app/config.ru:3:in `block in <main>'  2016-06-15T13:59:04.817299+00:00 app[web.1]:    from /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'  2016-06-15T13:59:04.817311+00:00 app[web.1]:    from /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/tsort.rb:345:in `each'  2016-06-15T13:59:04.817557+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'  2016-06-15T13:59:04.817569+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'  2016-06-15T13:59:04.817581+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'  2016-06-15T13:59:04.817706+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'  2016-06-15T13:59:04.817718+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'  2016-06-15T13:59:04.817679+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:272:in `start'  2016-06-15T13:59:04.817494+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'  2016-06-15T13:59:04.817642+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in `app'  2016-06-15T13:59:04.817694+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/server.rb:80:in `start'  2016-06-15T13:59:04.817604+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'  2016-06-15T13:59:04.817668+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'  2016-06-15T13:59:04.817730+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'  2016-06-15T13:59:04.817741+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'  2016-06-15T13:59:04.817753+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'  2016-06-15T13:59:04.817766+00:00 app[web.1]:    from bin/rails:9:in `require'  2016-06-15T13:59:04.817778+00:00 app[web.1]:    from bin/rails:9:in `<main>'  2016-06-15T13:59:05.665224+00:00 heroku[web.1]: State changed from starting to crashed  2016-06-15T13:59:05.650547+00:00 heroku[web.1]: Process exited with status 1  2016-06-15T13:59:26.741479+00:00 heroku[api]: Starting process with command `bundle exec rake db:seed` by fifiteen82726@gmail.com  2016-06-15T13:59:30.434725+00:00 heroku[run.6473]: Awaiting client  2016-06-15T13:59:30.466997+00:00 heroku[run.6473]: Starting process with command `bundle exec rake db:seed`  2016-06-15T13:59:30.664434+00:00 heroku[run.6473]: State changed from starting to up  2016-06-15T13:59:40.978644+00:00 heroku[run.6473]: Process exited with status 0  2016-06-15T13:59:40.990366+00:00 heroku[run.6473]: State changed from up to complete  2016-06-15T13:59:51.272567+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=grape-pratice.herokuapp.com request_id=6e4b2d8f-f24e-470b-8f0c-06da7ec3e9f5 fwd="27.246.159.134" dyno= connect= service= status=503 bytes=  2016-06-15T13:59:53.113748+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=grape-pratice.herokuapp.com request_id=498adafb-029b-4b6e-8c3c-99e16e9ab355 fwd="27.246.159.134" dyno= connect= service= status=503 bytes=  2016-06-15T14:01:10.487283+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/v1/dodc" host=grape-pratice.herokuapp.com request_id=a2cc2661-8eeb-47fd-ad6e-3c1c4c6974d9 fwd="27.246.159.134" dyno= connect= service= status=503 bytes=  2016-06-15T14:01:12.498807+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=grape-pratice.herokuapp.com request_id=2fbff81f-bac4-48b9-a857-440b19a0c1ce fwd="27.246.159.134" dyno= connect= service= status=503 bytes=  2016-06-15T14:01:12.949340+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/v1/doc" host=grape-pratice.herokuapp.com request_id=ccf66e59-26e1-4776-9011-29b7ecd40d27 fwd="27.246.159.134" dyno= connect= service= status=503 bytes=  2016-06-15T14:01:15.107664+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=grape-pratice.herokuapp.com request_id=a93858c7-849e-4b47-add2-2e0003f3513a fwd="27.246.159.134" dyno= connect= service= status=503 bytes=  Coda:grape_pra Coda$   

BTW, I put something img, css and js on public folder, and use <link href="xxx" and <script src="xxx" to load it (cause I download swagger-ui directly and only moved the html to view ), should I add this into pipeline list?

If I need to post some file, please tell me thanks.

Rails: One Parent & Multiple Nested Children With Independent Views: 'Link_to' to other child's index

Posted: 15 Jun 2016 07:28 AM PDT

I have one parent called user with multiple nested children resources (emails and phonenumber) with independent views using the code shown in: http://blog.8thcolor.com/en/2011/08/nested-resources-with-independent-views-in-ruby-on-rails/ , only I want the

 <%= link_to 'Next', ect... %>   

in the show.html.erb of the email child to link to the index.html.erb page of the phonenumber one.

The views are independent, and there are multiple users so it is important to retain the id of the parent when the view jumps from the show.html of the emails child to the index.html of phonenumber.

but nothing I try works. A couple of things I have tried inside the email's show.html.erb file are:

<%= link_to 'Next', user_phonenumber_path(@user) %>  <%= link_to 'Next', polymorphic_url([@parent, @phonenumber]) %>  

I've even tried just going back up to user without success via

but get the following error: No route matches {:action=>"show", :controller=>"customers", :customer_id=>"25"} missing required keys: [:id]

Any help would be appreciated.

Thank you,

Wex

An error occurred while installing active_shipping (0.9.13), and Bundler cannot continue

Posted: 15 Jun 2016 07:09 AM PDT

When I run bundle install it gives the following error:

An error occurred while installing active_shipping (0.9.13), and Bundler cannot continue.  Make sure that `gem install active_shipping -v '0.9.13'` succeeds before bundling.  

But did install gem install active_shipping -v '0.9.13' before running bundle install. How could I fix it? Thanks!

xxxxxx:~/code/inventory$ gem install active_shipping -v '0.9.13'  Successfully installed active_shipping-0.9.13  1 gem installed  xxxxxx:~/code/inventory$ bundle install  Ignoring json-1.8.3 because its extensions are not built.  Try: gem pristine json --version 1.8.3  /usr/lib/ruby/vendor_ruby/bundler.rb:284: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777  Fetching source index from https://rubygems.org/  Resolving dependencies...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................  Using rake (10.5.0)   Using Ascii85 (1.0.2)   Using ZenTest (4.9.5)   Using RubyInline (3.12.2)   Using i18n (0.7.0)   Using multi_json (1.11.3)   Using activesupport (3.2.22.2)   Using builder (3.0.4)   Using activemodel (3.2.22.2)   Using erubis (2.7.0)   Using journey (1.0.4)   Using rack (1.4.7)   Using rack-cache (1.6.1)   Using rack-test (0.6.3)   Using hike (1.2.3)   Using tilt (1.4.1)   Using sprockets (2.2.3)   Using actionpack (3.2.22.2)   Using mime-types (1.25.1)   Using polyglot (0.3.5)   Using treetop (1.4.15)   Using mail (2.5.4)   Using actionmailer (3.2.22.2)   Using active_utils (2.2.3)   Using json (1.8.3)   Using money (4.0.2)   Using macaddr (1.0.0)   Using uuid (2.3.7)   Using active_shipping (0.9.13) from git://github.com/optoro/active_shipping.git (at master)   NoMethodError: undefined method `spec' for nil:NilClass  An error occurred while installing active_shipping (0.9.13), and Bundler cannot continue.  Make sure that `gem install active_shipping -v '0.9.13'` succeeds before bundling.  

Updating default value in select_tag with Ajax call

Posted: 15 Jun 2016 06:51 AM PDT

I have a select_tag attribute within a ruby application. However, the default value obtains information from a database - Often that information is changed via an Ajax call and I was just wondering how one would be able to update a default value within a select_tag widget. Here is the following code:

= select_tag 'setup_form_popup', options_for_select([ ["No Setup Time","0"],["15 Minute", "15"], ["30 Minute", "30"], ["45 Minute", "45"], ["60 Minute", "60"], ["75 Minute", "75"], ["90 Minute","90"], ["105 Minute", "105"],["120 Minute","120"]], @event.setup_time), {:prompt => 'Setup Time'}  

where @event.setup_time is the default when the page is run ... however when there is an Ajax request, it is not updated as the view is not reloaded. Any and all help is appreciated. Cheers~

Which action for single-action controller that merely redirects?

Posted: 15 Jun 2016 07:38 AM PDT

I have an app where I try to stay adherent to REST.

The app receives requests for external links that doesn't belong to the app, so the sole purpose of the action is to redirect the request to the external URL.

My suggestion is to have the following controller/action: redirects_controller#create.

Is my thinking correct or should it be the show action instead?

GCM rails files location?

Posted: 15 Jun 2016 06:42 AM PDT

I was trying to implement gcm on my ror app , GCM on google chrom

I was following these https://developers.google.com/web/fundamentals/getting-started/push-notifications/?hl=en

It states that, we need to create main.js ,sw.js , manifest.json

In it says that, create these files in top of your app directory , but i'm having doubts abot these

Where should be these files located in rails ?

and am i doing anything wrong, is this the right way to get this task done, Can anybody help me with this?

Ruby on Rails 4.2.6 Undefined Method page_id

Posted: 15 Jun 2016 06:57 AM PDT

This is the error that I'm getting: undefined method `page_id' for #Page:0x0000000b2c1e28.

Showing C:/Users/eiria/Sites/simple_cms/app/views/sections/_form.html.erb where line #6 raised:

undefined method `page_id' for # Trace of template inclusion: app/views/sections/new.html.erb

Rails.root: C:/Users/eiria/Sites/simple_cms

I'm trying to nest Sections inside Pages for my Content Management System.

This is my Sections form:

<%= error_messages_for(@section) %>    <table summary="Section form fields">      <tr>          <th><%= f.label(:page_id, "Page") %></th>          <td><%= f.select(:page_id, @pages.map {|s| [s.name, s.id]}) %></td>      </tr>        <tr>          <th><%= f.label(:name) %></th>          <td><%= f.text_field(:name) %></td>      </tr>        <tr>          <th><%= f.label(:position) %></th>          <td><%= f.select(:position, 1..@section_count) %></td>      </tr>        <tr>          <th><%= f.label(:visible) %></th>          <td><%= f.select(:visible, {"Visible" => 1, "Hidden" => 2}) %></td>      </tr>        <tr>          <th><%= f.label(:content_type) %></th>          <td><%= f.select(:content_type, ['text', 'HTML']) %></td>      </tr>        <tr>          <th><%= f.label(:content) %></th>          <td><%= f.text_area(:content, :size => '40x10') %></td>      </tr>  </table>  

This is my Sections controller:

class SectionsController < ApplicationController    layout "admin"      before_action :confirm_logged_in    before_action :find_page      def index      @sections = @page.sections.sorted      @subject = @page.subject    end      def show      @section = Section.find(params[:id])    end      def new      @section = Section.new({:page_id => @page.id, :name => "Default"})      @pages = Page.order('position ASC')      @section_count = Section.count + 1    end      def create      @section = Section.new(section_params)        if @section.save        flash[:notice] = "Section created successfully."        redirect_to(:action => 'index', :page_id => @page.id)      else        @pages = Page.order('position ASC')        @section_count = Section.count + 1        render('new')      end    end      def       @section = Section.find(params[:id])      @pages = Page.order('position ASC')      @section_count = Section.count    end      def update      @section = Section.find(params[:id])        if @section.update_attributes(section_params)        flash[:notice] = "Section updated successfully."        redirect_to(:action => 'show', :id => @section.id, :page_id => @page.id)      else        @section = Section.find(params[:id])        @pages = Page.order('position ASC')        @section_count = Section.count        render('')      end    end      def delete      @section = Section.find(params[:id])    end      def destroy      section = Section.find(params[:id]).destroy      flash[:notice] = "Section '#{section.name}' destroyed succsessfully."      redirect_to(:action => 'index')    end      private      def section_params        params.require(:section).permit(:page_id, :name, :permalink, :position, :visible, :content_type, :content)      end        def find_page        if params[:page_id]          @page = Page.find(params[:page_id])          @subject = @page.subject        end      end  end  

Section model:

class Section < ActiveRecord::Base      belongs_to :page      has_many :section_edits      has_many :editors, :through => :section_edits, :class_name => "AdminUser"        CONTENT_TYPES = ['text', 'HTML']        validates_presence_of :name      validates_length_of :name, :maximum => 255        validates_inclusion_of :content_type, :in => CONTENT_TYPES,      :message => "must be one of: #{CONTENT_TYPES.join(', ')}"      validates_presence_of :content        scope :visible, lambda { where(:visible => true) }      scope :invisible, lambda { where(:visible => false) }      scope :sorted, lambda { order("sections.position ASC") }      scope :newest_first, lambda { order("sections.created_at DESC") }  end  

Page model:

class Page < ActiveRecord::Base      belongs_to :subject      has_many :sections      has_and_belongs_to_many :editors, :class_name => "AdminUser"        validates_presence_of :name      validates_length_of :name, :maximum => 255        validates_presence_of :permalink      validates_length_of :permalink, :within => 3..255      validates_uniqueness_of :permalink        scope :visible, lambda { where(:visible => true) }      scope :invisible, lambda { where(:visible => false) }      scope :sorted, lambda { order("pages.position ASC") }      scope :newest_first, lambda { order("pages.created_at DESC") }  end  

I don't see why it says undefined method page_id for line 6, while the same is used for line 5 but theres apparently nothing wrong there...

Any help would be appreciated.

P.S: This is my first question on stackoverflow, so please forgive me for any obvious mistakes. This question is almost completely identical to this, but my problem is creating a new section and not it.

Rails: How to make strong parameters easy to read

Posted: 15 Jun 2016 07:20 AM PDT

My app has strong parameters as followings.

How can I make this code easy to read?

This line has a lot of attributes

my controller

  def create      @schedule = current_user.schedules.build(schedule_params)      ...    end      ...      def schedule_params      params.require(:schedule).permit(:title, :departure_date, rooms_attributes: [:id, :_destroy, :room, :room_address, :day, :ccy, :amount, events_attributes: [:id, :_destroy, :start_at, :end_at, :title, :detail, :category, :ccy, :amount, amounts_attributes: [:id, :_destroy, :ccy, :amount]]])    end  

It would be appreciated if you could give me any suggestion.

ruby on rails console isn't working, I am getting"Switch to inspect mode" on windows

Posted: 15 Jun 2016 06:04 AM PDT

When I run my rails console it is saying "Switch to inspect mode" .I am working on windows . Kindly help !

application server sleeps after 10 minutes

Posted: 15 Jun 2016 06:01 AM PDT

We have nginx server setup with unicorn as application server. nginx server sleeps after 10 minutes and not able to respond to any request after 10 minutes cycle. gem capistrano-unicorn is used to setup unicorn.

This is the server specifications

nginx/1.2.4
unicorn 4.6.3
rails 3.2
ruby 1.9.3

Why is my polymorphic association nil while the _id and _type fields are not?

Posted: 15 Jun 2016 07:28 AM PDT

I'm writing some tests for my Rails project. I've come to writing some tests around a polymorphic association, for which I have defined a fixture. However, when I try to access the polymorphically associated field on that fixture, it returns nil.

The strange part is that while the field itself is nil, the _id and _type fields that describe it are not.

This is the model:

class Comment < ActiveRecord::Base    default_scope { where(is_deleted: false) }      belongs_to :post, :polymorphic => true    belongs_to :user  end  

(In case it wasn't obvious, the post association is the polymorphic.)

This is the action in the controller that I'm trying to test:

class CommentsController < ApplicationController      # ...      def update      if @comment.update comment_params          puts @comment.post.nil?        puts @comment.post_id.nil?        puts @comment.post_type.nil?          if @comment.post_type == 'Question'          redirect_to url_for(:controller => :questions, :action => :show, :id => @comment.post.id)        else          redirect_to url_for(:controller => :questions, :action => :show, :id => @comment.post.question.id)        end      else        flash[:error] = "Comment failed to update."        if @comment.post_type == 'Question'          redirect_to url_for(:controller => :questions, :action => :show, :id => @comment.post.id)        else          redirect_to url_for(:controller => :questions, :action => :show, :id => @comment.post.question.id)        end      end    end      private      def comment_params        params.require(:comment).permit(:content, :post_type, :post_id)      end      # ...    end  

The test itself looks like this:

test "should update existing comment" do    sign_in users(:standard_user)    patch :update, :id => comments(:one).id, :comment => { :content => "ABCDEF GHIJKL MNOPQR STUVWX YZ" }    assert_not_nil assigns(:comment)    assert_not_nil assigns(:comment).post    assert_response(302)  end  

And, finally, the fixture for that existing comment (comments(:one)) is:

one:    user: standard_user    post: one (Answer)    content: ABCDEF GHIJKL MNOPQR  

Both the standard_user User fixture and the one Answer fixture are correctly defined.

Running the test gives me this error:

  2) Error:  CommentsControllerTest#test_should_update_existing_comment:  NoMethodError: undefined method `question' for nil:NilClass      app/controllers/comments_controller.rb:50:in `update'      test/controllers/comments_controller_test.rb:16:in `block in <class:CommentsControllerTest>'  

The three log lines near the top of the update action output true \n false \n false - i.e. that the post field is nil, but that post_id and post_type are not.

Why is this? What can I do to fix it? I have no ID fields defined in my fixtures YAML, and I'd prefer not to have to specify the IDs (unless it can be done with ERB).

This is the entirety of the Answers fixture that the Comments depend on:

one:    body: ABCDEF GHIJKL MNOPQR STUVWX YZ ABCDEF GHIJKL MNOPQR STUVWX YZ    score: 0    question: one    user: standard_user    two:    body: ABCDEF GHIJKL MNOPQR STUVWX YZ ABCDEF GHIJKL MNOPQR STUVWX YZ    score: 0    question: one    user: editor  

That in turn depends on this Question fixture:

one:    title: ABCDEF GHIJKL MNOPQR STUVWX YZ    body: ABCDEF GHIJKL MNOPQR STUVWX YZ ABCDEF GHIJKL MNOPQR STUVWX YZ    tags:      - ABCDEF      - GHIJKL      - MNOPQR    score: 0    user: standard_user  

Undefined method scope for ActiveRecord_Relation

Posted: 15 Jun 2016 06:49 AM PDT

Why scope that I defined doesn't work? part of my code below:

users habtm messages  projects habtm messages  

Message.rb

scope :new_messages,-> { where(msg_status: 'new') }  scope :without_project,-> { includes(:messages_projects).where('messages_projects.project_id' => nil) } #<---this one    def mymethod    new_messages = Message.new_messages    @users = User.active.joins(:messages).merge(Message.new_messages).uniq    @users.each do |user|     new_users_messages = new_messages.without_projects.includes(:messages_users).where('messages_users.user_id' => user.id)    end  end  

but if I make query directly it works:

new_users_messages = new_messages.includes(:messages_projects).where('messages_projects.project_id' => nil).includes(:messages_users).where('messages_users.user_id' => user.id)  

Can anybody explain to me why it happens?

Update here is log, but nothing interesting

User Load (20.0ms)  SELECT DISTINCT "users".* FROM "users" INNER JOIN "accounts" ON "accounts"."user_id" = "users"."id" INNER JOIN "messages_users" ON "messages_users"."user_id" = "users"."id" INNER JOIN "messages" ON "messages"."id" = "messages_users"."message_id" WHERE "accounts"."blocked" = $1 AND "messages"."msg_status" = $2 AND "accounts"."email_notify" = $3  [["blocked", "f"], ["msg_status", "new"], ["email_notify", "t"]]    Message Load (0.5ms)  SELECT "messages".* FROM "messages" WHERE "messages"."msg_status" = $1  [["msg_status", "new"]]  Completed 500 Internal Server Error in 3116ms (ActiveRecord: 38.0ms)    NoMethodError (undefined method `without_projects' for #<Message::ActiveRecord_Relation:0x0000000a805fc0>):    app/models/message.rb:24:in `block in sender'    app/models/message.rb:23:in `sender'    app/controllers/groups_controller.rb:47:in `index'        Rendered /.rvm/gems/ruby-2.0.0-p647/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (19.6ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (5.3ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.9ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (36.4ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.7ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.5ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.4ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.3ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (30.8ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.4ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.6ms)    Rendered /.rvm/gems/ruby-2.0.0-p647/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (78.9ms)  

Cannot run rspec with filter tags

Posted: 15 Jun 2016 06:10 AM PDT

I have spec

RSpec.describe SearchFlight::Jet::SearchFlightRequest do    describe 'send search ticket request to Jetstar website', http_request: true do      context 'search ticket round trip successfully' do        # initialize        it 'return status 200' do          # my expects here ...        end      end    end  end  

When I run rspec on my iterm, it couldn't run

bundle exec rspec -t ~http_request  zsh: no such user or named directory: http_request  

Maybe it related to zsh command line (issue). I try to remove zsh from my iTerms 2 but it's not success. Any alternative shell for Rails dev ? Thanks

Rubymine syntax higlighting in js.erb files

Posted: 15 Jun 2016 06:53 AM PDT

I have javascript files that have embedded ruby. While functionally everything works fine, the syntax higlighting as well as the error inspection function of RubyMine 2016 has issues with that.

The first time i embed ruby in the javascript file by using the <%= ... %> syntax, something goes horribly wrong. See attached screenshot. I guess that RubyMine interprets the < sign as a comparison operator.

As i assume that embedding ruby in JavaScript is quite common, is there a way to make RubyMine play nice with my functional (and correct) code?

Otherwise it looks like i have a huge number of errors, and editing becomes quite unintuitive:

over 9000 errors

debugger in rails with byebug not working

Posted: 15 Jun 2016 05:51 AM PDT

I have a problem when I try using debugger in rails with byebug...I installed the byebug gem without any problems ... in gemfile :

group :development, :test do    gem 'sqlite3'    gem 'byebug'  end  

put the debugger in my controller:

class ArticlesController < ApplicationController    before_action :set_article, only: [:edit, :update, :show, :destroy]      def new        @article = Article.new    end      def create        debugger        @article = Article.new(article_params)        # @article.user = User.first      if @article.save        flash[:success] = "Article was successfully created"        redirect_to article_path(@article)      else        render 'new'      end    end      def show    end      def index      @articles = Article.all    end      def edit    end      def update      if @article.update(article_params)        flash[:success] = "Article was successfully updated"        redirect_to article_path(@article)      else          render 'edit'      end    end      def destroy      @article.destroy      flash[:danger] = "Article was successfully deleted"      redirect_to articles_path      end      private      def set_article          @article = Article.find(params[:id])      end      def article_params          params.require(:article).permit(:title, :description)      end    end  

(I am using gitbash in windwos 7 ) The problem is when I try calling article_params I get a blank line only for long time with no respond I tried to restart my server and and tried debugging again but same problem....Here is an image for the problem

here is the code from git bash (is the same in the image):

    5:          @article = Article.new      6:  end      7:      8:   def create      9:                  debugger  => 10:          @article = Article.new(article_params)     11:          # @article.user = User.first     12:     if @article.save     13:       flash[:success] = "Article was successfully created"     14:       redirect_to article_path(@article)  (byebug) article_params  -(here goes the blank line)  

Any one can help please?

Serving custom errors for route constraint failures (Rails)

Posted: 15 Jun 2016 05:26 AM PDT

Got a Rails 4 application that has routes wrapped in a basic ApiConstraint class that checks that the user has the proper value for the Accept header:

# app/routes.rb  scope(module: "v1", defaults: { format: :json }, constraints: ApiConstraint.new(version: 1)) do    # routes  end      # lib/api_constraint.rb  class ApiConstraint    attr_reader :version      def initialize(options)      @version = options[:version] || 1    end      def matches?(request)      regex = /.../      !!request.headers['Accept'].match(regex)    end  end  

That's all good, but I'd like a little more robustness with regards to error handling (a simple true/false coming from matches? isn't enough). Is it possible to somehow only do this check once and serve a proper 415 Unsupported Media Type error? I say once because I think I see a workaround in just doing the check again at the bottom of routes.rb e.g.:

match '*any', via: :all, to: -> (env) do    if env["HTTP_ACCEPT"].match(/.../)      [415, {}, "{ \"error\": \"Bad Accept header or something ... \" }"]    else      [404, {}, [ApiErrors.not_found.to_json]]    end  end  

But that just seems really sloppy. I'd like to avoid using external stuff like faraday and whatnot. I feel like this has to be possible in Rails, and I'm just not sure of the syntax. All the other SO questions/blog posts I've looked at don't seem to mention this kind of functionality at all. Any response appreciated. Thanks.

Capybara: Set value of summernote textarea

Posted: 15 Jun 2016 05:15 AM PDT

I'm trying to test a implementation of summernote 0.8.1.0 in my Rails app.

I realized that fill_in won't work because fill_in only works with html form elements and summernote is using a DIV with the contenteditable attribute.

I found a solution from here: http://stackoverflow.com/a/30921215/1713912, but it doesn't work for me.

Any ideas for a solution is much appreciated!

My test:

it "allows admins to add text blocks to events", js: true, focus: true do      click_on "Add text block"      expect(page).to have_content "Text block content"      all("div[contenteditable]").last.set("Dummy text")      click_on "Publish now"      expect(page).to have_content "Event created successfully"      expect(Event.last.text_blocks.last.text_attachment.content).to eq "Dummy text"  end  

Can not store time in database

Posted: 15 Jun 2016 05:34 AM PDT

I have used the Time.new method in my rails application to get the current date and I want to store this date into a variable of type datetime . I am using postgresql. Now if I insert the date of this format manually into table using pgAdminIII ,it is working fine but if I try to insert the time into the table via a controller code then it is storing a different date time into table.

For example suppose the current time is:-

2016-06-15 17:29:29

And if I insert this date and time into the table manually by copying this line from webpage then it is working fine.

But my controller code to store it into table is inserting something else like

2016-06-15 11:41:39

Note: I have used only Time.new (time region is not specified in my code)

Why update action is invoked when submitting form with non-changed data in Rails 4?

Posted: 15 Jun 2016 07:14 AM PDT

I load data from two tables to the single form. On the form I create new record for model B (child) while don't change anything for model A (parent). If for model B something is entered wrongly (for example, email address without '.com') then validation error for model B is displayed. After correcting the issue (put correct email) and pressing Submit button the update action for model A is invoked. But in model A there were no changes! Why update action for model A is being invoked in this case? There is no data to update to the database.

Below is more detailed explanation:

I use one signup form to enter data for two models: Tenant and User. Any tenant will have many users. When new user wants to signup he also enters data about his tenant (company). If entered tenant doesn't exist then new tenant is created along with new user. This part is working well. The problem is when new user enters the name of tenant that already exists in the database and ONLY if user will enter something wrong (for example, wrong email format). If something was entered wrong then validation error (for example, Email can't be blank) occurs AND all previously saved users of the same tenant are also displayed as a result of render 'new' in TenantController.

To display only the new record for which validation error was triggered I added <% if u.object.new_record? %> to the signup form (maybe this is not the right way to do this?):

  <%= f.fields_for(:users) do |u| %>      <% if u.object.new_record? %>      ...      <% end %>    <% end %>  

In this case the signup form is displayed correctly, BUT when I correct the cause of the validation error (for example, enter correct email) and press Save button, then update action is executed instead of create action. And this is the problem, because I don't want any user to be able to update tenant data at signup stage. At signup user should be able to create only his personal data, not update his tenant's data. Please suggest the way to do this.

Tenant model:

class Tenant < ActiveRecord::Base      has_many :users, dependent: :destroy, inverse_of: :tenant    accepts_nested_attributes_for :users          before_validation do       self.status = 0       self.name = name_orig.upcase       email.downcase!    end      validates :name_orig, presence: true, length: { maximum: 255 }      validates :name, uniqueness: { case_sensitive: false }      VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i    validates :email, presence: true, length: { maximum: 255 },                      format: { with: VALID_EMAIL_REGEX },                      uniqueness: { case_sensitive: false }      validates :status, presence: true    end  

User model:

class User < ActiveRecord::Base      belongs_to :tenant, inverse_of: :users      before_validation do       self.status = 0      self.email = email.downcase    end      validates :tenant, presence: true      VALID_USERNAME_REGEX = /\A\w+\s?\w*\z/i    validates :name,  presence: true, length: { maximum: 50 },                      format: { with: VALID_USERNAME_REGEX },                      uniqueness: { case_sensitive: false }      VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i    validates :email, presence: true, length: { maximum: 255 },                      format: { with: VALID_EMAIL_REGEX },                      uniqueness: { case_sensitive: false }      has_secure_password    validates :password, presence: true, length: { minimum: 6 }      validates :status, presence: true    end  

Tenant controller:

class TenantsController < ApplicationController      def show      @tenant = Tenant.find(params[:id])    end      def new      @tenant = Tenant.new      @tenant.users.build    end      def create      @tenant = Tenant.find_by(name: tenant_params[:name_orig].upcase)      if @tenant == nil        @tenant = Tenant.new(name_orig: tenant_params[:name_orig],                              email: tenant_params[:email])        @user = @tenant.users.build(tenant_params[:users_attributes]["0"])        @tenant.save        if @tenant.save          flash[:success] = "Welcome!"          redirect_to @user   # redirects to user profile        else          render 'new'        end      else        @user = @tenant.users.build(tenant_params[:users_attributes]["0"])        if @user.save          flash[:success] = "Welcome!"          redirect_to @user   # redirects to user profile        else          render 'new'        end      end    end         private        def tenant_params        params.require(:tenant).permit(:name_orig, :email,            users_attributes: [:name, :email, :password, :password_confirmation])      end  end  

Signup form:

<%= form_for(@tenant) do |f| %>      <%= render 'shared/tenant_error_messages' %>      <%= f.label :name_orig, "Company name" %>    <%= f.text_field :name_orig, class: 'form-control' %>      <%= f.label :email, "Company e-mail" %>    <%= f.email_field :email, class: 'form-control' %>      <%= f.fields_for(:users) do |u| %>      <% if u.object.new_record? %>        <%= u.label :name, "User name" %>        <%= u.text_field :name, class: 'form-control' %>          <%= u.label :email, "User e-mail" %>        <%= u.email_field :email, class: 'form-control' %>          <%= u.label :password, "Password" %>        <%= u.password_field :password, class: 'form-control' %>          <%= u.label :password_confirmation, "Password confirmation" %>        <%= u.password_field :password_confirmation, class: 'form-control' %>      <% end %>    <% end %>      <%= f.submit "Save", class: "btn btn-primary" %>  <% end %>  

Why is my Heroku app memory footprint so big

Posted: 15 Jun 2016 04:59 AM PDT

I have a Rails 4.2 application running on Heroku, Ruby version is 2.2.4

When I restart the application, using Heroku´s log-runtime-metrics the app logs this:

sample#memory_total=102.07MB   sample#memory_rss=102.06MB   sample#memory_cache=0.00MB   sample#memory_swap=0.00MB   sample#memory_pgpgin=29936pages   sample#memory_pgpgout=3807pages   sample#memory_quota=512.00MB  

A simple click to a diferent page in the landing of the app reports these details:

sample#memory_total=267.07MB   sample#memory_rss=265.63MB   sample#memory_cache=1.43MB   sample#memory_swap=0.00MB   sample#memory_pgpgin=109878pages   sample#memory_pgpgout=41509pages   sample#memory_quota=512.00MB  

Oink reports: Memory usage: 435416

Entering the app I have some datatables with pagination, when moving around the pages the memory keeps increasing:

sample#memory_total=349.68MB   sample#memory_rss=348.18MB   sample#memory_cache=1.50MB   sample#memory_swap=0.00MB   sample#memory_pgpgin=159122pages   sample#memory_pgpgout=69604pages   sample#memory_quota=512.00MB  

Oink reporting at this moment: Memory usage: 602352

If I go out to a simpler page on the app Heroku reports:

sample#memory_total=353.05MB   sample#memory_rss=351.51MB   sample#memory_cache=1.54MB   sample#memory_swap=0.00MB   sample#memory_pgpgin=169306pages   sample#memory_pgpgout=78924pages   sample#memory_quota=512.00MB  

Oink reports Memory usage: 604744

After 5 minutes moving around Heroku reports for memory total something between 360 and 400+ MB. It doesn't get into Memory Quota errors but if a new web worker would be fired I bet it would.


I have also taken some data from ObjectSpace. Navigating around the site (this time in local), first with the simplest pages, then entering the part with pagination with fetches more data, going out and so. These are some of the logs from ObjectSpace.count_objects:

{:TOTAL=>556379, :FREE=>1142, :T_OBJECT=>27740, :T_CLASS=>7356, :T_MODULE=>1563, :T_FLOAT=>9, :T_STRING=>241807, :T_REGEXP=>2481, :T_ARRAY=>92685, :T_HASH=>16081, :T_STRUCT=>1118, :T_BIGNUM=>13, :T_FILE=>117, :T_DATA=>81408, :T_MATCH=>6132, :T_COMPLEX=>1, :T_RATIONAL=>909, :T_SYMBOL=>1691, :T_NODE=>62347, :T_ICLASS=>11779}

{:TOTAL=>556379, :FREE=>1211, :T_OBJECT=>27540, :T_CLASS=>7354, :T_MODULE=>1565, :T_FLOAT=>9, :T_STRING=>241100, :T_REGEXP=>2478, :T_ARRAY=>93344, :T_HASH=>16763, :T_STRUCT=>1078, :T_BIGNUM=>13, :T_FILE=>122, :T_DATA=>81422, :T_MATCH=>6031, :T_COMPLEX=>1, :T_RATIONAL=>911, :T_SYMBOL=>1690, :T_NODE=>61968, :T_ICLASS=>11779}

{:TOTAL=>556379, :FREE=>946, :T_OBJECT=>24257, :T_CLASS=>7523, :T_MODULE=>1565, :T_FLOAT=>9, :T_STRING=>251448, :T_REGEXP=>2362, :T_ARRAY=>83078, :T_HASH=>15272, :T_STRUCT=>1175, :T_BIGNUM=>63, :T_FILE=>128, :T_DATA=>89152, :T_MATCH=>5952, :T_COMPLEX=>1, :T_RATIONAL=>963, :T_SYMBOL=>2028, :T_NODE=>58656, :T_ICLASS=>11801}

ENTERING DATATABLES, WITH PAGINATION, 25 RECORDS PER PAGE, DATA RETRIEVED CONTAINS UNIQUE STRINGS (ADDRESSES IN FACT).

{:TOTAL=>556379, :FREE=>906, :T_OBJECT=>26280, :T_CLASS=>7363, :T_MODULE=>1563, :T_FLOAT=>9, :T_STRING=>252024, :T_REGEXP=>2474, :T_ARRAY=>87445, :T_HASH=>15347, :T_STRUCT=>1144, :T_BIGNUM=>16, :T_FILE=>133, :T_DATA=>80601, :T_MATCH=>6686, :T_COMPLEX=>1, :T_RATIONAL=>985, :T_SYMBOL=>1690, :T_NODE=>59906, :T_ICLASS=>11806}

{:TOTAL=>556379, :FREE=>146, :T_OBJECT=>18752, :T_CLASS=>7359, :T_MODULE=>1563, :T_FLOAT=>9, :T_STRING=>295002, :T_REGEXP=>2304, :T_ARRAY=>81885, :T_HASH=>13791, :T_STRUCT=>867, :T_BIGNUM=>15, :T_FILE=>11, :T_DATA=>77634, :T_MATCH=>847, :T_COMPLEX=>1, :T_RATIONAL=>1251, :T_SYMBOL=>1679, :T_NODE=>41463, :T_ICLASS=>11800}

{:TOTAL=>571870, :FREE=>433, :T_OBJECT=>19352, :T_CLASS=>7369, :T_MODULE=>1565, :T_FLOAT=>9, :T_STRING=>294098, :T_REGEXP=>2358, :T_ARRAY=>91079, :T_HASH=>14983, :T_STRUCT=>879, :T_BIGNUM=>15, :T_FILE=>16, :T_DATA=>77945, :T_MATCH=>1128, :T_COMPLEX=>1, :T_RATIONAL=>1591, :T_SYMBOL=>2028, :T_NODE=>45197, :T_ICLASS=>11824}

{:TOTAL=>628109, :FREE=>343, :T_OBJECT=>20647, :T_CLASS=>7360, :T_MODULE=>1563, :T_FLOAT=>9, :T_STRING=>318169, :T_REGEXP=>2346, :T_ARRAY=>115854, :T_HASH=>17767, :T_STRUCT=>949, :T_BIGNUM=>15, :T_FILE=>10, :T_DATA=>79152, :T_MATCH=>1243, :T_COMPLEX=>1, :T_RATIONAL=>1789, :T_SYMBOL=>1685, :T_NODE=>47405, :T_ICLASS=>11802}

{:TOTAL=>727564, :FREE=>470, :T_OBJECT=>22820, :T_CLASS=>7361, :T_MODULE=>1563, :T_FLOAT=>9, :T_STRING=>362350, :T_REGEXP=>2390, :T_ARRAY=>152959, :T_HASH=>22342, :T_STRUCT=>1035, :T_BIGNUM=>33, :T_FILE=>11, :T_DATA=>81286, :T_MATCH=>2167, :T_COMPLEX=>1, :T_RATIONAL=>2497, :T_SYMBOL=>1686, :T_NODE=>54779, :T_ICLASS=>11805}

{:TOTAL=>811122, :FREE=>392, :T_OBJECT=>24361, :T_CLASS=>7362, :T_MODULE=>1563, :T_FLOAT=>9, :T_STRING=>409740, :T_REGEXP=>2434, :T_ARRAY=>176571, :T_HASH=>25118, :T_STRUCT=>1076, :T_BIGNUM=>51, :T_FILE=>13, :T_DATA=>82701, :T_MATCH=>2858, :T_COMPLEX=>1, :T_RATIONAL=>3093, :T_SYMBOL=>1686, :T_NODE=>60285, :T_ICLASS=>11808}

LEAVING NOW DATATABLES AND PAGINATION TO A SIMPLER PAGE ON THE APP

{:TOTAL=>819681, :FREE=>494, :T_OBJECT=>24601, :T_CLASS=>7374, :T_MODULE=>1563, :T_FLOAT=>9, :T_STRING=>413540, :T_REGEXP=>2437, :T_ARRAY=>178899, :T_HASH=>25953, :T_STRUCT=>1118, :T_BIGNUM=>93, :T_FILE=>14, :T_DATA=>83043, :T_MATCH=>2924, :T_COMPLEX=>1, :T_RATIONAL=>3121, :T_SYMBOL=>1688, :T_NODE=>60999, :T_ICLASS=>11810}


I also can get gc profiler data. But what worries me there is that most of the reported data and allocated stuff if from gems that are required and I need anyway.


So...

I'm on my way trying to detect memory leaks, or the reason why memory footprint is so high, and reduce it as much as I can. Any advices how to proceed from here are welcome.

It would be nice to understand why after a first click - after restarting - the reported memory by Heroku doubles, though I imagine that it is after that when most of the objects get constructed and memory allocated.

But then the difference between what Oink reports and what Heroku reports is huge, I guess Oink reports in Bytes. And again I imagine that they are reporting different things, or at least Heroku is reporting about much more stuff.

Any good hints how to interpret all this data? Isn't it a 300-400 MB memory footprint too much for a Heroku app?

Thanks.

getting error on destroy item

Posted: 15 Jun 2016 06:17 AM PDT

i have 1 crud of project and i am trying to destroy project from list as using ajax.

class ProjectsController < ApplicationController  .  .  .   def destroy      @project.destroy      respond_to do |format|        format.js      end    end    end  

destroy.js

$('#all_projects').html("<%= escape_javascript render(:partial => 'projects/all_projects') %>");  

all_projects.html.erb

<table>    <thead>      <tr>        <th>Name</th>        <th>Team size</th>        <th colspan="3"></th>      </tr>    </thead>      <tbody>      <% @projects.each do |project| %>        <tr>          <td><%= project.name %></td>          <td><%= link_to 'Show', project %></td>          <td><%= link_to 'Edit', edit_project_path(project) %></td>          <td><%= link_to 'Destroy', project, method: :delete, data: { confirm: 'Are you sure?' } ,:remote=>true%></td>        </tr>      <% end %>    </tbody>  </table>  

index.html.erb

<h1>Listing Projects</h1>    <div id="all_project">    <%= render 'projects/all_projects'%>  </div>  

when i try to load all project its working fine. but when i destroy project it will give me error in server side like below.

ActionView::Template::Error (undefined method `each' for nil:NilClass):       9:   </thead>      10:       11:   <tbody>      12:     <% @projects.each do |project| %>      13:       <tr>      14:         <td><%= project.team_size %></td>    app/views/projects/_all_projects.html.erb:12:in `_app_views_projects__all_projects_html_erb___3489379756657223366_70218666904220'  

what i missed to do please help me to find. thanks

calling a grape API endpoint directly from the browser results in UncaughtThrowError

Posted: 15 Jun 2016 05:03 AM PDT

If I call an api endpoint directly from the web and the execution of the code runs into an error then the error thrown from the

error!

function is not handled. I receive an: UncaughtThrowError

The same error does not happen if I call the same api from curl or swagger. Any help is appreciated.

The code samples are below:

In the API endpoint I have a before filter:

  before { restrict_access_to_developers }  

The restrict_access_to_developers looks like this:

def restrict_access_to_developers    header_token = headers.try(:fetch,'Api-Key'){ nil }    key = ApiKey.where token: header_token    Rails.logger.info "API call: #{headers}\tWith params: #{params.inspect}" if ENV['DEBUG']    if key.blank?      error_code = ErrorCodes::DEVELOPER_KEY_MISSING      error_msg = 'please aquire a developer key'      error!({ :error_msg => error_msg, :error_code => error_code }, 401)  

So the error! method which is provided by the grape throws an :error but that is not handled...

Error when doing rake db:migrate PG::ConnectionBad: fe_sendauth: no password supplied

Posted: 15 Jun 2016 04:50 AM PDT

So I've launched Postgres and I'm unable to do migration on my Cloud9 Rails instance.. I supplied password for a user and it say that there is no password supplied. I get this error:

Running via Spring preloader in process 4339  rake aborted!  PG::ConnectionBad: fe_sendauth: no password supplied  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:87:in `connection'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:916:in `initialize'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:823:in `new'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:823:in `up'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/migration.rb:801:in `migrate'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/tasks/database_tasks.rb:137:in `migrate'  /usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'  /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'  /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'  /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'  /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'  -e:1:in `<main>'  Tasks: TOP => db:migrate  (See full trace by running task with --trace)  

database.yml

default: &default    adapter: postgresql    encoding: unicode    pool: 5    username: <%= ENV['USERNAME'] %>    password: <%= ENV['PASSWORD'] %>    host: <%= ENV['IP'] %>    development:    <<: *default    database: app_development  

Ruby On Rails format_measure() or measure()

Posted: 15 Jun 2016 04:50 AM PDT

What is the difference between the Ruby On Rails function measure() and format_measure() ???

Thank you

How to avoid quering multiple times in serializer?

Posted: 15 Jun 2016 05:03 AM PDT

I have a Model story.rb with field product_ids. it is a Arrayof ids. in story_controller show action i have to return a story with it's products and stores. i am returning response through story_serializer. like this

Note: story has no association with store

class StorySerializer < ActiveModel::Serializer    ----    ----   def products      here my query for products using `product_ids`   end     def stores      here is the problem      to find stores, i have to find product's first and then find store's of that product. so again i am quering for products here.   end    end  

I have product_ids so i can easily returns all the related products of that story, but the problem is to return related stores. How can i return store's without quering for products again. Any suggestions would be helpfull.

Facing Redis issue with sidekiq on rails4 spree application

Posted: 15 Jun 2016 04:36 AM PDT

Hello I am facing issue of redis on staging. Issue is Redis::CommandError (ERR max number of clients reached): My findings are as follows ::

  1. Increase work_process from 2 to 3 in unicorn.rb I had tried this but its not helpful for us.
    1. Find out heroku add ons for redis rediscloud, redisgreen, redismonitor, redistogo.
    2. Not able to operate redis-cli on staging server.

Please guide me to solve this issue.

Check if there are any unique tokens left of a certain character length

Posted: 15 Jun 2016 06:49 AM PDT

I have a Post model with the attribute token.

I'm using SecureRandom.urlsafe_base64(length_of_token) to create a token.

The token doesn't need to be unguessable, but must be unique.

I'm starting with tokens 1 character long, and when they are all used up (all 64 combinations), I should move on to have tokens that are 2 characters long.

How should I check if there are any token variations left for tokens that are 3 characters long?

LIFO except FIFO in Sidekiq

Posted: 15 Jun 2016 04:19 AM PDT

Is it possible to achieve LIFO except FIFO in Sidekiq? The reason is that my queue grew up to 190000 jobs and newer jobs are more important than old ones.

react-rails - can't import react-router 'Link' in external file

Posted: 15 Jun 2016 04:14 AM PDT

I've been trying to modularize my react-rails project as I currently have everything in one jsx file (not good practise - still learning)

I've set up some files in a components folder which the main home.js.jsx file is reading - but one of the external components requires use of 'Link' from React router. The component ('Property') isn't read when I try to include link at the top of the file. Basic premise is that the 'properties' component takes all of the property data and renders each of them into a 'property' component.

File structure:  -assets    -javascripts      -home.js.jsx      -components        -_properties.js.jsx        - _property.js.jsx  

This is the relavent parts of the main home.js.jsx file, first showing how I require react-router:

//home.js.jsx    import { browserHistory, Router,IndexRoute,  Route, Link } from 'react-router';  

And then showing where the 'Properties' component is called:

//home.js.jsx    var listPropertiesLayout = React.createClass({    ....    ....    render: function(){      console.log('home js rendering the properties component');      return(        <div>          <h1>Search for Properties</h1>          <Properties data={this.state.data} />        </div>      )    }  })  

This is the _properties.js.jsx file that takes all of the property data:

var Properties = React.createClass({    render: function() {      console.log('hit the external properties component file');      var propertyNodes = this.props.data.map(function(property) {        return (          <Property title={property.name} action="show" key={property.id} id={property.id}>            {property.description}          </Property>        );      });      return (        <div className="propertyList">          {propertyNodes}        </div>      );    }  });  

Then the problem arises below. When I try to include 'Link' from react-router it fails to read the component. ('Property is not defined'):

import { Link } from 'react-router';      var Property = React.createClass({    rawMarkup: function() {      var converter = new Showdown.converter()      var rawMarkup = converter.makeHtml(this.props.children.toString(), {sanitize: true});      return { __html: rawMarkup };    },    render: function() {      var editTrue = "";      var editTrue2 = ""      if(this.props.action == "edit"){        editTrue = <Link to={{ pathname: `/property/${this.props.id}/edit`, state: { modal: true, returnTo: `/property/${this.props.id}/edit` } }}>{this.props.title} </Link>        editTrue2 = <Link to={{ pathname: `/property/${this.props.id}/edit`, state: { modal: true, returnTo: `/property/${this.props.id}/edit` } }}> <img src="http://placekitten.com/100/100" alt="{this.props.name}" /></Link>       }else{        editTrue = <Link to={{ pathname: `/property/${this.props.id}`, state: { modal: true, returnTo: `/property/${this.props.id}` } }}>{this.props.title} </Link>        editTrue2 = <Link to={{ pathname: `/property/${this.props.id}`, state: { modal: true, returnTo: `/property/${this.props.id}` } }}> <img src="http://placekitten.com/100/100" alt="{this.props.name}" /></Link>         }  

If I take out the import line, it reads the property component fine but obviously fails because 'Link' is undefined. I've tried various methods of importing/exporting the component but having no luck. Does anybody know how this could work? Is there a basic way of export the 'react-router' library to be read across all of the files? Thanks in advance.

No comments:

Post a Comment