Saturday, November 5, 2016

Add index to Rails form object | Fixed issues

Add index to Rails form object | Fixed issues


Add index to Rails form object

Posted: 05 Nov 2016 08:13 AM PDT

Add a index when using Rails Form Objects to update multiple records

Issue I'm having is when I need to create multiple records for the same model The hash created by the form overwrites identical models

form_for @post_form do |f|    ...    f.text_field :article    f.text_field :article    ...      Parameters: {"post_form"=>{"article"=>"article 2"}}  

I'm using a Form Object to update multiple different models with some of the fields being created client side with ajax

I need a way to add an index to get around the overwriting when creating multiple records with the same model.

gocardless webhook signature mismatch

Posted: 05 Nov 2016 08:12 AM PDT

I am going through the gocardless getting started guide, but when I try to setup a webhook (sandbox mode), I don't get the correct value.

The code is copy-pasted from https://developer.gocardless.com/getting-started/api/staying-up-to-date-with-webhooks/#building-a-webhook-handler

and looks like this

computed_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'),                                               secret,                                               request.raw_post)    provided_signature = request.headers['Webhook-Signature']    Rack::Utils.secure_compare(provided_signature, computed_signature)    # => false  

What am I missing? Thanks for any help

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "options" does not exist

Posted: 05 Nov 2016 08:05 AM PDT

allo. i get this error when i try to "heroku run rake db:migrate" :

rake aborted!  ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "options" does not exist  LINE 5:                WHERE a.attrelid = '"options"'::regclass                                            ^  :               SELECT a.attname, format_type(a.atttypid, a.atttypmod),                       pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod                  FROM pg_attribute a LEFT JOIN pg_attrdef d                    ON a.attrelid = d.adrelid AND a.attnum = d.adnum                 WHERE a.attrelid = '"options"'::regclass                   AND a.attnum > 0 AND NOT a.attisdropped                 ORDER BY a.attnum  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `async_exec'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec_no_cache'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:138:in `block in exec_query'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:915:in `column_definitions'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:174:in `columns'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:208:in `columns'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:217:in `columns_hash'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `block in valid?'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `each'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `all?'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `valid?'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:18:in `method_missing'  /app/app/models/option.rb:4:in `get_config_value'  /app/app/models/achat.rb:17:in `<class:Achat>'  /app/app/models/achat.rb:1:in `<top (required)>'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:329:in `require_or_load'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:288:in `depend_on'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:206:in `require_dependency'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `each'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `block in eager_load!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `each'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `eager_load!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:347:in `eager_load!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `each'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'  /app/config/environment.rb:5:in `<top (required)>'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application.rb:249:in `block in run_tasks_blocks'  /app/vendor/bundle/ruby/2.2.0/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'  PG::UndefinedTable: ERROR:  relation "options" does not exist  LINE 5:                WHERE a.attrelid = '"options"'::regclass                                            ^  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `async_exec'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec_no_cache'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:138:in `block in exec_query'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:915:in `column_definitions'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:174:in `columns'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:208:in `columns'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:217:in `columns_hash'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `block in valid?'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `each'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `all?'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:60:in `valid?'  /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:18:in `method_missing'  /app/app/models/option.rb:4:in `get_config_value'  /app/app/models/achat.rb:17:in `<class:Achat>'  /app/app/models/achat.rb:1:in `<top (required)>'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:329:in `require_or_load'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:288:in `depend_on'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:206:in `require_dependency'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `each'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `block in eager_load!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `each'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `eager_load!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/engine.rb:347:in `eager_load!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `each'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'  /app/config/environment.rb:5:in `<top (required)>'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'  /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'  /app/vendor/bundle/ruby/2.2.0/gems/railties-4.0.0/lib/rails/application.rb:249:in `block in run_tasks_blocks'  /app/vendor/bundle/ruby/2.2.0/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'  Tasks: TOP => db:migrate => environment  (See full trace by running task with --trace)  '  

but when i run "rake db:migrate" on my computer it run fine. can anybody help me please. i work with rails 4.0.0, ruby 2.2.3, Postgres SGBD and i'm in linuxmint 17

Rails validate state if account is active

Posted: 05 Nov 2016 07:28 AM PDT

the user of the app have to ativate there account before the can edit or delete the entry.

How can i set the state from inactive to active? I'm using the state_machine from pluginaweek to set the states.

state_machine initial: :inactive do  event :activate do      state = 'active'    end  end  

My controller called the activate-action will send via email to the user.

def activate  @entry = Entry.find([:id])  if (check_email_link(@entry.exp_date))    if @entry.save      flash[:notice] = t("activate")      redirect_to @entry      else        flash[:error] = t("already_activated")        redirect_to @entry    end   else    flash[:error] = t("timeout")    redirect_to @entry.new  end  

end the documentation say that i can set the Städte via entry.state but rhis won't work.

Why will the entry not activated? Can every help me?

How to deploy a Rails application through Core FTP

Posted: 05 Nov 2016 07:39 AM PDT

I am trying to deploy my Rails application to a hosting site through Core FTP. I set up all the required settings in Core FTP. So, I transferred the files through Core FTP.

But, when I went to my webpage, it just showed the list of all the files.

My webpage

So, my question is, how can I deploy those files properly, so that it shows the webpage instead of the list of website files?

Rails Routes Format

Posted: 05 Nov 2016 05:42 AM PDT

Need to generate the following routes as

/:owner_name/articles  /:articles/:id  /owners  /:owner_name  

I have tried as,

resources :owners, param: :owner_name, path: '', shallow_path: "", only: [:index, :show] do  resources :articles, only: [:index,:show]  end   

But cant able to reproduce the same

Why is activerecord-import using type_cast_for_database instead of value_for_database

Posted: 05 Nov 2016 04:54 AM PDT

Tracking Rails 5 source code, it turns out that its way to get SQL value for database of a column can be simplified as follows: ActiveRecord::Base.connection.quote(attribute.value_for_database)

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute.rb

However I noticed that activerecord-import gem, uses another method type_cast_for_database(attr_name, value), and it passes it the value of the attribute before_type_cast https://github.com/zdennis/activerecord-import/blob/master/lib/activerecord-import/import.rb#L639

Also I noticed that calling type_cast_for_database(column_name, value_before_typecast) is faster than calling attribute.value_for_database as the former is reduced to calling type.serialize(value_before_type_cast), while the latter is reduced to type.serialize(type_cast(value_before_type_cast))

So why does rails uses the extra step of type casting the attribute value before passing it to serialize? As it appears that activerecord-import works fine without the need of this step.

Ruby-on-rails: are there any other way to make page statefull except use session?

Posted: 05 Nov 2016 07:29 AM PDT

I am creating search form for model with some tabs, radiobuttons, dropbox, etc. I use index action for searching and sorting. Parameters for searching is persisted in params. It works while I stay in the same index view. But if I had to visit other page and then come back to search page again, params doesn't work and state is not persisted.

I know I can do it with session, but suppose I would have more search forms for another models and so all that params goes into session. Doesn't it make session messy?

So question is: Is there other reasonable way to persist page state (but I don't want to put into database)

trouble creating an test_app on Ruby on rails?

Posted: 05 Nov 2016 06:16 AM PDT

Its showing some error like

Please help me resolving this

Ubuntu, Ruby, Ruby on Rails Installation Problems (Cant visit localhost:3000)

Posted: 05 Nov 2016 02:38 AM PDT

This is my first time learning to code, first time on Linux and first time on stackeroverflow so I dont know if its glaringly obvious where I have gone wrong.

I have followed this guide https://gorails.com/setup/ubuntu/16.04 and everything was working as the guide said until I got to this section:

run bundle install --local /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- bundler (LoadError) from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' from /usr/lib/ruby/vendor_ruby/rails/generators/app_base.rb:328:in bundle_command' from /usr/lib/ruby/vendor_ruby/rails/generators/app_base.rb:344:inrun_bundle' from (eval):1:in run_bundle' from /usr/lib/ruby/vendor_ruby/thor/command.rb:27:inrun' from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:126:in invoke_command' from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:133:inblock in invoke_all' from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:133:in each' from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:133:inmap' from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:133:in invoke_all' from /usr/lib/ruby/vendor_ruby/thor/group.rb:232:indispatch' from /usr/lib/ruby/vendor_ruby/thor/base.rb:440:in start' from /usr/lib/ruby/vendor_ruby/rails/commands/application.rb:17:in' from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' from /usr/lib/ruby/vendor_ruby/rails/cli.rb:14:in <top (required)>' from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' from /usr/bin/rails:9:in' tom@Laptop:~$ cd myapp tom@Laptop:~/myapp$ rake db:create rake aborted! LoadError: cannot load such file -- bundler/setup /home/tom/myapp/config/boot.rb:3:in <top (required)>' /home/tom/myapp/config/application.rb:1:in' /home/tom/myapp/Rakefile:4:in <top (required)>' (See full trace by running task with --trace) tom@Laptop:~/myapp$ rails server /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire': cannot load such file -- bundler/setup (LoadError) from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' from /home/tom/myapp/config/boot.rb:3:in' from bin/rails:3:in require_relative' from bin/rails:3:in'

Sorry I don't know how to format this correctly. When I visit localhost:3000 I just get Network error.

Has anyone got any idea how to solve this? Thanks for your time.

Rails 5, Bootstrap Carousel not rendering - setup

Posted: 05 Nov 2016 04:09 AM PDT

Im trying to use an image carousel in my Rails 5 app. I'm trying to follow the approach in this article: https://www.toptal.com/ruby-on-rails/rails-helper-bootstrap-carousel

I have an models for proposal and image. The associations are:

Proposal

has_many :images, as: :imageable      accepts_nested_attributes_for :images,  reject_if: :all_blank, allow_destroy: true  

Image

belongs_to :imageable, :polymorphic => true, optional: true  

My view partial has:

    <!-- GALLERY -->    <div id="myCarousel" class="carousel slide" data-ride="carousel">    <!-- <div class="carousel-inner" role="listbox"> -->   <% @images.each do |gallery| %>      <% if gallery == @images.order(created_at: :asc).first%>      <div class="item active">       <%= carousel_for(gallery) %>         <%= image_tag(gallery.picture.url, :class => "carousel_image", :style => "text-align: center" ) %>           <div class="carousel_caption">              <p style="text-align: center"><%= gallery.comment.humanize %></p>                <p style="text-align: center"><%= gallery.credit %></p>          </div>        </div>      <% else %>       <div class="item">      <%= carousel_for(gallery) %>       <%= image_tag(gallery.picture, :class => "carousel_image") %>        <div class="carousel_caption">          <p style="text-align: center"><%= gallery.comment.humanize %></p>            <p style="text-align: center"><%= gallery.credit %></p>        </div>      </div>     <% end %>  <% end %>  <!-- </div> -->      <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>      <span class="sr-only">Previous</span>    </a>    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>      <span class="sr-only">Next</span>    </a>  </div>  <!-- /GALLERY -->  

Helper has:

module CarouselHelper    def carousel_for(images)      Carousel.new(self, images).html    end      class Carousel      def initialize(view, images)        @view, @images = view, images        @uid = SecureRandom.hex(6)      end        def html        content = safe_join([indicators, slides, controls])        content_tag(:div, content, id: uid, class: 'carousel slide')      end        private        attr_accessor :view, :images, :uid      delegate :link_to, :content_tag, :image_tag, :safe_join, to: :view        def indicators        items = images.count.times.map { |index| indicator_tag(index) }        content_tag(:ol, safe_join(items), class: 'carousel-indicators')      end        def indicator_tag(index)        options = {          class: (index.zero? ? 'active' : ''),          data: {             target: uid,             slide_to: index          }        }          content_tag(:li, '', options)      end        def slides        items = images.map.with_index { |image, index| slide_tag(image, index.zero?) }        content_tag(:div, safe_join(items), class: 'carousel-inner')      end        def slide_tag(image, is_active)        options = {          class: (is_active ? 'item active' : 'item'),        }          content_tag(:div, image_tag(image), options)      end        def controls        safe_join([control_tag('left'), control_tag('right')])      end        def control_tag(direction)        options = {          class: "#{direction} carousel-control",          data: { slide: direction == 'left' ? 'prev' : 'next' }        }          icon = content_tag(:i, '', class: "glyphicon glyphicon-chevron-#{direction}")        control = link_to(icon, "##{uid}", options)      end    end  end  

My application.js has:

//= require jquery  //= require jquery_ujs  //= require turbolinks  //= require jquery-fileupload/vendor/jquery.ui.widget  //= require jquery-fileupload/jquery.iframe-transport  //= require jquery-fileupload/jquery.fileupload  //= require bootstrap-sprockets  //= require moment  //= require bootstrap-datetimepicker  //= require pickers  //= require underscore  //= require gmaps/google  //= require markerclusterer  //= require cocoon  //= require_tree .  

When I try this, I get an error that says:

undefined method `count' for #<Image:0x007fb10c88bea8>  

It highlights this line of the carousel (indicators method):

  items = images.count.times.map { |index| indicator_tag(index) }  

ARUN'S SUGGESTION

<div id="myCarousel" class="carousel slide" data-ride="carousel">    <!-- <div class="carousel-inner" role="listbox"> -->   <%# @images.each do |gallery| %>      <%# if gallery == @images.order(created_at: :asc).first%>      <div class="item active">       <%= carousel_for(@images) %>         <%= image_tag(@image.picture.url, :class => "carousel_image", :style => "text-align: center" ) %>           <div class="carousel_caption">              <p style="text-align: center"><%= @image.comment.humanize %></p>                <p style="text-align: center"><%= @image.credit %></p>          </div>        </div>      <%# else %>       <div class="item">      <%= carousel_for(@images) %>       <%= image_tag(@image.picture, :class => "carousel_image") %>        <div class="carousel_caption">          <p style="text-align: center"><%= @image.comment.humanize %></p>            <p style="text-align: center"><%= @image.credit %></p>        </div>      </div>     <%# end %>  <%# end %>  <!-- </div> -->      <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>      <span class="sr-only">Previous</span>    </a>    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>      <span class="sr-only">Next</span>    </a>  </div>  <!-- /GALLERY -->  

ERROR SAYS: undefined method `picture' for nil:NilClass

2nd attempt at Arun's suggestion

<div id="myCarousel" class="carousel slide" data-ride="carousel">        <div class="item active">       <%= carousel_for(@images) %>         <%= image_tag(@image.picture.url, :class => "carousel_image", :style => "text-align: center" ) %>           <div class="carousel_caption">              <p style="text-align: center"><%= @image.comment.humanize %></p>                <p style="text-align: center"><%= @image.credit %></p>          </div>        </div>       <div class="item">      <%= carousel_for(@images) %>       <%= image_tag(@image.picture.url, :class => "carousel_image") %>        <div class="carousel_caption">          <p style="text-align: center"><%= @image.comment.humanize %></p>            <p style="text-align: center"><%= @image.credit %></p>        </div>      </div>   <!-- </div> -->      <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>      <span class="sr-only">Previous</span>    </a>    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>      <span class="sr-only">Next</span>    </a>  </div>  <!-- /GALLERY -->  

Error says: undefined method `picture' for nil:NilClass

Arun's revised suggestion

Taking Arun's revised suggestion, I try replacing the entire gallery view, with:

<%= carousel_for(Image.all.map(&:picture_url)) %>       

When i try to render the page, the first image is rendered. I can see from the chrome inspector, that the second image is recognised, although the carousel doesnt work. The chevrons don't move the images along. There are no js issues showing in the console.

Error while deploying rails app on aws elasticbeanstalk through ubuntu command line?

Posted: 05 Nov 2016 02:20 AM PDT

I have used the below links for my rails app deployment to aws.

https://medium.com/@jatescher/how-to-set-up-a-rails-4-2-app-on-aws-with-elastic-beanstalk-and-postgresql-3f9f29c046e2#.1j40p1fa8

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Ruby_rails.html

Database for development: sqlite3

Database for production: postgresql

Server: puma

after running "eb deploy" command, I'm facing the below error:

ERROR: [Instance: i-somevalue] Command failed on instance. Return code: 1 Output: (TRUNCATED)...undle. Add it to Gemfile. /var/app/ondeck/config/environment.rb:5:in <top (required)>' /opt/rubies/ruby-2.3.1/bin/bundle:23:inload' /opt/rubies/ruby-2.3.1/bin/bundle:23:in `' Tasks: TOP => environment (See full trace by running task with --trace). Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].

ERROR: Unsuccessful command execution on instance id(s) 'i-somevalue'. Aborting the operation.

ERROR: Failed to deploy application.

Traceback (most recent call last):

File "/usr/local/bin/eb", line 9, in load_entry_point('awsebcli==3.8.3', 'console_scripts', 'eb')()

File "/usr/local/lib/python2.7/dist-packages/ebcli/core/ebcore.py", line 150, in main app.run()

File "/usr/local/lib/python2.7/dist-packages/cement/core/foundation.py", line 797, in run return_val = self.controller._dispatch()

File "/usr/local/lib/python2.7/dist-packages/cement/core/controller.py", line 472, in _dispatch return func()

File "/usr/local/lib/python2.7/dist-packages/cement/core/controller.py", line 478, in _dispatch return func()

File "/usr/local/lib/python2.7/dist-packages/ebcli/core/abstractcontroller.py", line 57, in default self.do_command()

File "/usr/local/lib/python2.7/dist-packages/ebcli/controllers/deploy.py", line 94, in do_command staged=self.staged, timeout=self.timeout, source=self.source)

File "/usr/local/lib/python2.7/dist-packages/ebcli/operations/deployops.py", line 45, in deploy can_abort=True)

File "/usr/local/lib/python2.7/dist-packages/ebcli/operations/commonops.py", line 91, in wait_for_success_events if _is_success_string(event.message):

File "/usr/local/lib/python2.7/dist-packages/ebcli/operations/commonops.py", line 264, in _is_success_string raise ServiceError(message) ebcli.objects.exceptions.ServiceError: Failed to deploy application.

update country_state_select gem

Posted: 05 Nov 2016 02:45 AM PDT

i want to update country_state_select gem...

This is my Gemfile

gem 'country_state_select'  gem 'chosen_rails'  gem 'compass-rails'  

And after bundle ,i will start my rails application rails s

I have error,it look ilke

NoMethodError - undefined method `state_options' for CountryStateSelect:Module:    app/views/shared/users/_light_box_login.html.erb:101:in `block in _app_views_shared_users__light_box_login_html_erb___390633241__632173138'    actionview (4.2.7.1) lib/action_view/helpers/capture_helper.rb:38:in `block in capture'    actionview (4.2.7.1) lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'    actionview (4.2.7.1) lib/action_view/helpers/capture_helper.rb:38:in `capture'    actionview (4.2.7.1) lib/action_view/helpers/form_helper.rb:444:in `form_for'    simple_form (3.3.1) lib/simple_form/action_view_extensions/form_helper.rb:26:in `block in simple_form_for'    simple_form (3.3.1) lib/simple_form/action_view_extensions/form_helper.rb:45:in `with_simple_form_field_error_proc'    simple_form (3.3.1) lib/simple_form/action_view_extensions/form_helper.rb:25:in `simple_form_for'    app/views/shared/users/_light_box_login.html.erb:44:in `_app_views_shared_users__light_box_login_html_erb___390633241__632173138'    actionview (4.2.7.1) lib/action_view/template.rb:145:in `block in render'  

And i find solution

i mean gem 'country_state_select', '3.0.1'

But when add this gem and bundle,i have another issue..

Fetching gem metadata from https://rubygems.org/...........  Fetching version metadata from https://rubygems.org/...  Fetching dependency metadata from https://rubygems.org/..  Resolving dependencies...  Bundler could not find compatible versions for gem "compass-rails":    In snapshot (Gemfile.lock):      compass-rails (= 3.0.2)      In Gemfile:      compass-rails        country_state_select (= 3.0.1) was resolved to 3.0.1, which depends on        compass-rails (~> 2.0.4)    Running `bundle update` will rebuild your snapshot from scratch, using only  the gems in your Gemfile, which may resolve the conflict.  

Anyone help me..how to update that gem version..

Rails 5.0.0 jsonapi-parser can't find in any sources

Posted: 05 Nov 2016 06:20 AM PDT

I got that error when I tried to setup new Rails 5.0.0 application. When I running 'bundle' command, I'm getting this one: Could not find jsonapi-parser-0.1.1.beta2 in any of the sources In my Gemfile.lock only 'active_model_serializers' depends from jsonapi witch depend from 'jsonapi-parser'.

How can I fix it?

Using Devise to set up referrals issue

Posted: 05 Nov 2016 01:58 AM PDT

I am running devise to handle user authentication, I am wondering if any of you have experience in setting one up with devise?

I found this small post which is nice but am a bit confused as to how this line works:

def capture_referal    session[:referral] = params[:referral] if params[:referral]  end  

I can't see in that example where I am meant to input in the params[:referral] ?

Also this seems kind of simple, is the referral token going to be the referral code the user sets e.g RAILSDEVISE or will it be the entire URL x.com?ref=RAILSDEVISE?

If anyone has a github of a rails referral program i'd love to check it out(:

Remove Rails from OSX

Posted: 05 Nov 2016 01:36 AM PDT

Actually the problem is that i want to remove rails from Os x.

how to change the default rails version in linux

Posted: 05 Nov 2016 06:01 AM PDT

I had all rails version gems install till 5.0.1 but when I do

rails -v  Rails 3.1.3  

I want to update/change it rails version to 4.3.6. How can I achieve it.

Note: I had install ruby & rails using rbenv

rails c not working in rails 5

Posted: 05 Nov 2016 12:42 AM PDT

On using the command in terminal inside a rails 5 application

rails c  

the error thrown is given bellow. I have no idea what this means in a similar question here that for which the solution was to use spring stop. I have tried that too but no it still gave the same error. it would be great if somebody can point out the mistake here.

Running via Spring preloader in process 6457  /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require': dlopen(/Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)    Referenced from: /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle    Reason: image not found - /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'      from /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/completion.rb:10:in `<top (required)>'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:3:in `<top (required)>'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:138:in `require_command!'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:68:in `console'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'      from /Users/AmanChawla/Desktop/NewApp/bin/rails:9:in `<top (required)>'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'      from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'      from /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'      from /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'      from -e:1:in `<main>'  

how to validate a specific email pattern in ruby on rails

Posted: 05 Nov 2016 03:20 AM PDT

I am currently designing a sign up page, in my model/user.rb file, how do I specify that only these email addresses ending with @gmail.com can be successfully registered? Thank you

Preview last uploaded image

Posted: 05 Nov 2016 03:35 AM PDT

I'm using an old project where I could upload many images but for this one, I only need just one. When uploaded, I should see what's uploaded (preview). When first uploaded, I see the image. If uploaded a different image, I still see the first image. I dont want that, I need to preview the last uploaded image.

JavaScript:

$('.receipt.upload').on('change', function(e) {    let id = e.target.id;    let files = e.target.files;    let image = files[0];    let reader = new FileReader();    reader.onload = function(file) {      let img = new Image();      console.log(file);      img.src = file.target.result;      $('.'+id).replaceWith(img);    }    reader.readAsDataURL(image);    //console.log(files);  });  

Rails html.erb:

<div>    <%= image_tag('/assets/receipt/missing-receipt.jpg', class: "receipt#{contract.id}") %>  </div>    // Inside a form  <div>    <%= f.file_field :receipt, id: "receipt#{contract.id}" , class: "receipt upload"%>  </div>  

Change these makes no difference:

let files = e.target.files[0];  let image = files;  

Exclude all URL which is starting with `/blog/ and /event/`

Posted: 05 Nov 2016 03:36 AM PDT

I going to exclude all url which are starting with /blog/ and /event/

i tried with

filter => "ga:pagePath!=^/blog/;ga:pagePath!=^/blog/"  

But this expresssion not working.

Rails 5: Two forms for one polymorphic model on a single view

Posted: 04 Nov 2016 11:04 PM PDT

I have a polymorphic model, Comment, comment on a Post or another Comment (reddit style). I want a user to be able to comment directly to the post with a commentable_id of @post.id and a commentable_type of @post.class.name

OR

be able to comment on another comment on the same page, however, using @comment.id and @comment.class.name

Is there a way to dynamically change between @post or @comment depending on where the form is?

Here is the relevant information that I think might help.

My Form

# shared/_comment_form.html.erb  <div id="comment-form" class="form-group">    <%= form_for @comment, remote: true, url: post_comments_path(@post) do |f| %>      <%= f.text_area :body, required: true, rows: 5, class: "form-control" %>      <%= f.hidden_field :commentable_id, :value => @post.id %>      <%= f.hidden_field :commentable_type, :value => @post.class.name %>      <br>      <%= f.submit class: "btn btn-primary" %>    <% end %>  </div>  <span id="add-comment">Add a comment</span>  

And my view

# show.html.erb for a Post  <p id="notice"><%= notice %></p>  <h2>Post:</h2>  <div class="well">    <p>      <strong>Title:</strong>      <%= @post.title %>    </p>  <% if @post.description %>    <p>      <strong>Description:</strong>      <%= @post.description %>    </p>  <% end %>  </div>    <%= render "shared/comment_form" %>    <% if @post.comments.any? %>    <%= render "shared/comment_list" %> # Inside of this partial will be another comment form for the a comment.  <% else %>    <p>No comments yet</p>  <% end %>  

Inside the comment_list partial would be another partial of comment_form

# shared/_comment_list.html.erb  <h2>Comments</h2>  <ul>    <% @post.comments.each do |c| %>      <li><%= c.body %></li>        <%= render "shared/comment_form" %> # Here    <% end %>  </ul>  

EDIT:

I'm adding my routes too.

# Applicable routes   resources :forums do    resources :posts,     shallow: true do      resources :comments,  shallow: true    end  end  

And:

post_comments GET    /posts/:post_id/comments(.:format)     comments#index                       POST   /posts/:post_id/comments(.:format)     comments#create  new_post_comment GET    /posts/:post_id/comments/new(.:format) comments#new          edit_comment GET    /comments/:id/edit(.:format)           comments#edit               comment GET    /comments/:id(.:format)                comments#show                       PATCH  /comments/:id(.:format)                comments#update                       PUT    /comments/:id(.:format)                comments#update                       DELETE /comments/:id(.:format)                comments#destroy           forum_posts GET    /forums/:forum_id/posts(.:format)      posts#index                       POST   /forums/:forum_id/posts(.:format)      posts#create        new_forum_post GET    /forums/:forum_id/posts/new(.:format)  posts#new             edit_post GET    /posts/:id/edit(.:format)              posts#edit                  post GET    /posts/:id(.:format)                   posts#show                       PATCH  /posts/:id(.:format)                   posts#update                       PUT    /posts/:id(.:format)                   posts#update                       DELETE /posts/:id(.:format)                   posts#destroy                forums GET    /forums(.:format)                      forums#index                       POST   /forums(.:format)                      forums#create             new_forum GET    /forums/new(.:format)                  forums#new            edit_forum GET    /forums/:id/edit(.:format)             forums#edit                 forum GET    /forums/:id(.:format)                  forums#show                       PATCH  /forums/:id(.:format)                  forums#update                       PUT    /forums/:id(.:format)                  forums#update                       DELETE /forums/:id(.:format)                  forums#destroy  

I cant get my form to work on heroku using ruby on rails

Posted: 05 Nov 2016 02:06 AM PDT

I've spent the last 4 hours just trying different things to figure out why the emails and errors i get on heroku are happening. Im very new to Rails this is my second app, so please dumb it down and talk to me like a small child, lol

http://dev-match-matt-napper.herokuapp.com/contacts/new This is my heroku link and when you click submit it says something went wrong. I am following the simpleCodeCast on udemy videos, no response from him yet.

https://github.com/Mnapper3/simpleCodeCasts_saas this is my git hub the files (master) i used were:

app/controller/contacts_controller  app/mailers/contact_mailer  app/models/contact  app/contact_mailer/contact_email.html  app/views/contacts/new.html  

really hope i have given you enough info to help me, or maybe you could put in how you create form emailers? or link a video

P.S. im using cloud9 & if you clone this app you need to :

bundle install  bundle update  rake db:migrate  

then you'll be able to preview it.

Please help!!!
-Matt Napper

Rails assets usage clarification

Posted: 04 Nov 2016 11:20 PM PDT

I am new to rails and I'm a bit confused about how assets are loaded. I can get things working but I would like to understand what really happens behind the scenes.

I have been reading the documentation but there are things that I don't understand completely.

MANIFEST FILE

First thing that confuses me is the usage of manifest files.

For instance if in my app/assets/javascripts/application.js file I have:

//= require_tree .  

Rails documentation says:

tells Sprockets to recursively include all JavaScript files in the specified directory into the output

What isn't clear to me is which directory? app/assets/javascripts/?

Does that mean that if I add a file in app/assets/javascripts/ it will be loaded and served?

If I add a gem that requires to add a file example.js I need to add to the manifest file:

//= require example.js  

But why is this necessary if //= require_tree already loads and serve files in app/assets/javascripts/ which is the location where I have put my example.js? Ok that allows me to specify the order if later I add more requires. But other than that?

HTML FILE

And then the script to be included in application.html.erb

<%= javascript_include_tag ('application'), 'data-turbolinks-track' => true %>  

I understand this loads the application.js file mentioned above and therefore the various //= require in it.

Sometimes happens that is required to script the particular file as:

<script src="js/example.js"></script>  

Is this scenario wouldn't be <script src="js/example.js"></script> doing the exact same thing of //= require example.js?

PUBLIC VS APP ASSETS

I understand that if I place my example.js file on public/assets folder it won't be compiled but served separately. Why would I do that? Is it reasonable to do it in case a file is not served correctly when concatenated and compiled and works only if served separated? In other words, if I include a .js file on app/assest and it has problems to load or break things, is it worth to try to remove it from there and move it to public/assets or does this just not make sense?

APP ASSETS VS VENDOR ASSETS

On which scenario should I add a file to vendor assets instead of app assets? What is the difference between adding it to a place or another? And in my vendor/assets/javascripts I have only an empty .keep file. So there'n so such thing as manifest file on app/assets. How are files in this folder referenced then?

Google Analytics API 403 Error

Posted: 04 Nov 2016 09:50 PM PDT

Some times i am getting 403 error and After 12.00pm It's start working again.How can i solve this issue..

Google::APIClient::Request Result: 403 {"vary"=>"Origin, X-Origin", "content-type"=>"application/json; charset=UTF-8", "date"=>"Sat, 05 Nov 2016 04:38:25 GMT", "expires"=>"Sat, 05 Nov 2016 04:38:25 GMT", "cache-control"=>"private, max-age=0", "x-content-type-options"=>"nosniff", "x-frame-options"=>"SAMEORIGIN", "x-xss-protection"=>"1; mode=block", "server"=>"GSE", "alt-svc"=>"quic=\":443\"; ma=2592000; v=\"36,35,34\"", "connection"=>"close", "transfer-encoding"=>"chunked"}

FullCalendar dates and times rendered incorrect rails

Posted: 04 Nov 2016 09:45 PM PDT

FullCalendar implement in my RoR application, and today he is doing tests I realized that the dates and the days are incorrect. I worked well until this day, create a new application and the same thing happens, today is Monday, 4 November, and I get that it is not November 6

var initialize_calendar;  initialize_calendar = function() {    $('.calendar').each(function(){      var calendar = $(this);      calendar.fullCalendar({        header: {          left: 'prev,next today',          center: 'title',          today:    'hoy',          month:    'month',          week:     'week',          day:      'day',          right: 'month,agendaWeek,agendaDay'        },          allDayText: "Todo el dia",          buttonText: {          today: "Hoy",          month: "Mes",          week: "Semana",          day: "Hoy"        },          monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],        monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],        dayNames: ['Lunes', 'Martes', 'Miercoles', 'Jueves','Viernes', 'Sabado', 'Domingo'],        dayNamesShort: ['Lun', 'Mar', 'Mier', 'Jue', 'Vie', 'Sab', 'Dom'],        defaultView: 'agendaDay',        selectable: true,        minTime: '08:00:00',        maxTime: '20:00:00',        slotDuration: '00:60:00',        hiddenDays: [ 5, 6 ],        selectHelper: true,        editable: true,        eventLimit: true,        events: '/events.json',        timezone: "local",            select: function(start, end) {          $.getScript('/events/new', function() {            $('#event_date_range').val(moment(start).format("MM/DD/YYYY HH:mm") + ' - ' + moment(end).format("MM/DD/YYYY HH:mm"))            date_range_picker();            $('.start_hidden').val(moment(start).format('YYYY-MM-DD HH:mm'));            $('.end_hidden').val(moment(end).format('YYYY-MM-DD HH:mm'));          });            calendar.fullCalendar('unselect');        },          eventDrop: function(event, delta, revertFunc) {          event_data = {             event: {              id: event.id,              start: event.start.format(),              end: event.end.format()            }          };          $.ajax({              url: event.update_url,              data: event_data,              type: 'PATCH'          });        },          eventClick: function(event, jsEvent, view) {          $.getScript(event.edit_url, function() {            $('#event_date_range').val(moment(event.start).format("MM/DD/YYYY HH:mm") + ' - ' + moment(event.end).format("MM/DD/YYYY HH:mm"))            date_range_picker();            $('.start_hidden').val(moment(event.start).format('YYYY-MM-DD HH:mm'));            $('.end_hidden').val(moment(event.end).format('YYYY-MM-DD HH:mm'));          });        }      });    })  };  $(document).on('turbolinks:load', initialize_calendar);  

If link_to is clicked flash message on new page?

Posted: 05 Nov 2016 01:52 AM PDT

view

<% if current_user.challenges.badges.count > 0 %>    <%= link_to new_duel_path(:challenge_daddy => @user.id), class: "btn", style: "padding-top: 10px; padding-bottom: 10px; margin-top: 15px; color: white;" do %>      <span class='glyphicon glyphicon-tower'></span> Duel    <% end %>  <% else %>    # user will be sent to performance page    <%= link_to performance_path, class: "btn", style: "padding-top: 10px; padding-bottom: 10px; margin-top: 15px; color: white;" do %>      <span class='glyphicon glyphicon-tower'></span> Duel    <% end %>  <% end %>  

controller

def performance    @user = current_user    # only if the user is brought to performance via the above link_to should this be flashed    flash[:alert] =  "YOU'RE NOT AUTHORIZED TO INITIATE A DUEL UNTIL YOU BECOME A NINJA, BUT YOU CAN BE INVITED TO A DUEL"  end  

I tried to send the flash directly in link_to, but nothing happened: link_to performance_path(:alert => "Flash message") also tried (:error => "Flash message")

Css pulse Animation doesn't work

Posted: 04 Nov 2016 10:52 PM PDT

I can't figure out why my code doesn't work, hope somebody can help me.

Here is my code:

@-webkit-keyframes pulse  {    0%    {      -webkit-transform: scale3d(1, 1, 1);      transform: scale3d(1, 1, 1);    }    50%    {      -webkit-transform: scale3d(1.05, 1.05, 1.05);      transform: scale3d(1.05, 1.05, 1.05);    }    100%    {      -webkit-transform: scale3d(1, 1, 1);      transform: scale3d(1, 1, 1);    }  }    @keyframes pulse  {    0%    {      -webkit-transform: scale3d(1, 1, 1);      transform: scale3d(1, 1, 1);    }    50%    {      -webkit-transform: scale3d(1.05, 1.05, 1.05);      transform: scale3d(1.05, 1.05, 1.05);    }    100%    {      -webkit-transform: scale3d(1, 1, 1);      transform: scale3d(1, 1, 1);    }  }    .pulse   {    -webkit-animation-name: pulse;    animation-name: pulse;    animation-iteration-count: infinite;    -webkit-animation-iteration-count: infinite;  }
<html>    <head></head>    <body>      <h1 class="pulse">Thermostat-Einstellungen</h1>              <h2>Eingestellte Temperatur</h2>      <form action="web_event" id="eingestellte_temperatur_form" method="POST">        <input name="web_event[event_type]" type="hidden" value="desired_temp_change">        <input name="web_event[integer_value]" type="text" data-displayPrevious=true value="20" class="dial">      </form>      <hr/>      <h2>Aktuelle Temperatur</h2>      <form id="aktuelle_temp_form">        <input name="web_event[integer_value]" type="text" value=20 data-fgColor="#ffec03" data-skin="tron" class="dial">      </form>      <hr/>      <h2>Letzte Termperaturen</h2>      <div id="echtzeit_graph" class="wild_graph"></div>    </body>    </html>

In my last Project did this animation work just great but in my ruby on rails project i can't get the animation working

How to pass image URL in parameters to New?

Posted: 04 Nov 2016 08:33 PM PDT

This is what I've tried:

index

<%= link_to new_inspiration_path(inspiration: {image: inspiration.image}) %> # user clicks this  

controller

def new    @inspiration = current_user.inspirations.build(inspiration_params)  end    def inspiration_params    params.require(:inspiration).permit(:name, :image, :image_file_name, :image_content_type, :image_file_size, :image_updated_at)  end  

server

Started GET "/inspirations/new?inspiration_image=%2Fsystem%2Finspirations%2Fimages%2F000%2F000%2F069%2Foriginal%2Frule_1.jpg%3F1478260961" for 127.0.0.1 at 2016-11-04 08:10:41 -0400  Processing by InspirationsController#new as */*    Parameters: {"inspiration_image"=>"/system/inspirations/images/000/000/069/original/rule_1.jpg?1478260961"} # For example, this is the image url I'm trying to show in the _form    User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 129]]    Inspiration Load (0.4ms)  SELECT  "inspirations".* FROM "inspirations" WHERE "inspirations"."id" IS NULL LIMIT 1  Completed 400 Bad Request in 6ms  

_form

<%= simple_form_for(@inspiration, html: { data: { modal: true } }) do |f| %>     <%= image_tag @inspiration.image.url %> # doesn't show image, says "missing"    <%= f.file_field :image %>  <% end %>  

model

class Inspiration < ActiveRecord::Base    has_attached_file :image, :styles => { :medium => "300x300>", :small => "150x150>" }    validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]    belongs_to :user  end  

I get error: ActionController::RoutingError (No route matches [GET] "/images/original/missing.png"):

NoMethodError in Account::Posts#index

Posted: 04 Nov 2016 09:05 PM PDT

I'm doing Ruby101 tutorial, but get something wrong.

The rails log:

ActionView::Template::Error (undefined method `title' for nil:NilClass):  13:       <% @posts.each do |post| %>  14:         <tr>  15:           <td> <%= post.content %> </td>  16:           <td> <%= post.group.title %> </td>  17:           <td> <%= post.updated_at %> </td>  18:           <td> <%= link_to('Edit', edit_group_post_path(post.group, post), class: "btn btn-default btn-xs") %></td>  19:           <td> <%= link_to('Delete', group_post_path(post.group, post), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-default btn-xs") %></td>  

app/views/account/posts/index.html.erb:16:in block in _app_views_account_posts_index_html_erb___92982360307258762_69918747126320' app/views/account/posts/index.html.erb:13:in_app_views_account_posts_index_html_erb___92982360307258762_69918747126320' Rendering /home/zedong/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout Rendering /home/zedong/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb Rendered /home/zedong/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (3.7ms) Rendering /home/zedong/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb Rendered /home/zedong/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.5ms) Rendering /home/zedong/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb Rendered /home/zedong/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.7ms) Rendered /home/zedong/.rvm/gems/ruby-2.3.1/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (21.5ms)

And the group.rb:

class Group < ActiveRecord::Base    belongs_to :user    has_many :posts    validates :title, presence: true    has_many :group_relationships    has_many :members, through: :group_relationships, source: :user  end  

The post.rb:

class Post < ApplicationRecord    validates :content, presence: true    belongs_to :user    belongs_to :group      scope :recent, -> {order("created_at DESC")}  end  

Because I'm doing this tutorial at second time, so I compare it with the first time's code. And I have tried to copy the file one by one to find the problem, but it can't works. By the way, when i want to implement the eidt and delete button, something was wrong.

Project at here: github

16 comments:

  1. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for fre
    pg online

    ReplyDelete
  2. I read this article. I think You put a lot of effort to create this article. I appreciate your work.
    https://www.ufa365.info/

    ReplyDelete
  3. So luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site.
    แทงบอลสเต็ป

    ReplyDelete
  4. I went over this website and I believe you have a lot of wonderful information, saved to my bookmarks
    รีวิวเว็บพนัน

    ReplyDelete
  5. I must say, I thought this was a pretty interesting read when it comes to thisC topic. Liked the material. . .
    ufa365

    ReplyDelete
  6. Great post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments. Analytics shows they are coming to the site but I have a feeling “nobody wants to be first”. เว็บแทงบอลสเต็ปไม่มีขั้นต่ำ

    ReplyDelete
  7. Consequently, starting in the amount of electronic marketing strategy, is whenever a company's existing website, which will be to review the present site and its purpose is to improve the potency of the future. There is no evidence that the development and implementation of a method to be significantly different way of electronic marketing. Strategic planning for enterprise development or strategic marketing to comply with the established framework should still be
    เว็บแทงบอลออโต้

    ReplyDelete
  8. So luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site.
    แทงบาสเว็บไหนดี

    ReplyDelete
  9. Internet search engine optimization experts apply the modern analytics service, which has a positive affect a website. SEO companies are facing great competition in the SEO field. However, they introduce guaranteed SEO services to manage with the competition.

    บาคาร่าsa-gaming

    ReplyDelete
  10. his is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.
    แทงบาสออนไลน์

    ReplyDelete
  11. his is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.
    คาสิโนออนไลน์ฟรีโบนัส/

    ReplyDelete
  12. Daisy Limousine provides the best black car service in the tri-state area. We can provide limo service or airport service in New Jersey, New York, Rhode Island, Massachusetts, Pennsylvania, and Connecticut. Our on-time ground transportation service will drive you pretty much from A to B anywhere in the North East of America. Give us a call or book a ride online at your convenience
    lucky-god

    ReplyDelete
  13. The role of a cultural media manager has appealed to the mass generation of socially-active internet users. It's hard not to. Especially when some might think that you can earn big bucks from posting Facebook updates. Hardly.
    สล็อตออนไลน์

    ReplyDelete
  14. Add Index To Rails Form Object >>>>> Download Now

    >>>>> Download Full

    Add Index To Rails Form Object >>>>> Download LINK

    >>>>> Download Now

    Add Index To Rails Form Object >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete
  15. Add Index To Rails Form Object >>>>> Download Now

    >>>>> Download Full

    Add Index To Rails Form Object >>>>> Download LINK

    >>>>> Download Now

    Add Index To Rails Form Object >>>>> Download Full

    >>>>> Download LINK XH

    ReplyDelete