Friday, October 28, 2016

Modifying the request protocol in RSpec 3.5 | Fixed issues

Modifying the request protocol in RSpec 3.5 | Fixed issues


Modifying the request protocol in RSpec 3.5

Posted: 28 Oct 2016 08:27 AM PDT

I'm trying to modify the protocol of the request my controller test sends my server to be 'https://'. This is what I have so far:

require 'rails_helper'    RSpec.describe StripeWebhookController, type: :controller do    describe "POST #stripe_webhook", :type => :request do      let(:user) { create(:user, stripe_customer_id: '12345') }        context 'when request is authorized' do         before(:each) do          host! "api.stripe.com"        end          it 'returns 200 and sends a Transaction Error email if the Stripe customer exists in the DB' do          params = {            type: 'charge.failed',            data: {              object: {                customer: user.stripe_customer_id              }            }          }          response = post "/stripe_event", params          expect(response).to eq(200)        end      end   end  

and in my controller:

class StripeWebhookController < ApplicationController    before_action :validate_request    def validate_request      if Rails.env.production? || Rails.env.test?        return head status: 404 unless request.host == 'api.stripe.com' && request.protocol == 'https://'      end    end  end  

I've tried adding

protocol: :https  

and

protocol: 'https://'  

to the post request (as per Modifying the request protocol in RSpec 3.5), but I've not been able to get it to work. Any help would be much appreciated!

Rails 5 deprecation warning and adding code to initializers?

Posted: 28 Oct 2016 08:14 AM PDT

To which initializer file should I add the desired line of code? I'm getting the following deprecation warning.

DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This still causes Strings to be parsed as if they were in Time.zone, and Times to be converted to Time.zone.

To keep the old behavior, you must add the following to your initializer:

config.active_record.time_zone_aware_types = [:datetime]  

To silence this deprecation warning, add the following:

config.active_record.time_zone_aware_types = [:datetime, :time]  

I'm a rails newbie, I just want to follow best practice. Thanks!

Why are null values in your tables a bad thing to have?

Posted: 28 Oct 2016 08:07 AM PDT

I'm reading a post about single table inheritance and polymorphism in Rails and I came across this sentence:

STI isn't always the best design choice for your schema. If sub-classes that you intend to use for STI have many different data fields, then including them all in the same table would result in a lot of null values and make it difficult to scale over time. In this case, you may end up with so much code in your model sub-classes that the shared functionality between sub-classes is minimal and warrants separate tables.

Why is having null values in your table cells a bad thing? Does it take up memory? Does it slow down queries? What makes it bad?

Rails remove time from datetime attribute and group

Posted: 28 Oct 2016 08:06 AM PDT

I have a column DATENEW in my invoices table.

If in my view I use:

 <td><%= invoice.DATENEW %></td>  

it shows:

2015-02-16 11:38:03 UTC  

I need to display only year month and day. And I also need to group by DATENEW. So time should not be considered when grouping.

How can I do it?

Rails: storing static lookup types/constants outside database

Posted: 28 Oct 2016 08:13 AM PDT

I have static lookups that are used to populate form fields as well as validate attributes.

I'm not storing them in the database because they are static and will not change, and core application logic is based upon the values (don't want a DB value change breaking the application).

# 15+ different categories...  APPLICANT_TYPES = ["primary", "coborrower"].freeze    # forms...  <%= f.select :applicant_type, APPLICANT_TYPES %>    # models...  class Applicant < ApplicationRecord    validates :applicant_type, inclusion: { in: APPLICANT_TYPES }  end  

I have several options that are viable, but am not sure which one is the most conventional or may cause problems. What's the Rails convention for static constants like this?

  1. config/initializers/constants.rb
  2. ApplicationRecord that all models inherit from
  3. config/constants.yml doesn't seem preferible to me since there's the extra step to load YAML into Ruby, so why not just go with constants.rb above?

I'm a little confused because any of them will work, but I'm sure there are some unexpected side-effects I'm not considering.

How to publish and implement Ruby file to my website

Posted: 28 Oct 2016 07:42 AM PDT

I'm a beginner of Ruby. I want to establish my website by programming with Ruby language. Before that, I used to upload HTML files to my web-host server, so that I could update my website. But now I have no idea about what should I do with Ruby file.

Thank you!

Select records where many-to-many relationship is empty

Posted: 28 Oct 2016 07:37 AM PDT

I have a many-to-many relationship between folder and user

class Folder      has_many :folder_share_authorities, dependent: :destroy      has_many :shared_users, through: :folder_share_authorities, source: :user  end    class User      has_many :folder_share_authorities, dependent: :destroy      has_many :shared_folders, through: :folder_share_authorities, source: :folder  end    class FolderShareAuthority < ApplicationRecord      belongs_to :folder      belongs_to :user  end  

I have my folders table structured with ancestry gem.

Now, when I share a folder with an user (create a FolderShareAuthority relationship), how can I have all descendants of that folder also shared with that user too?

I also had a pair index to make sure one user only has 1 relationship with one folder. So I think I should select all descendants haven't been shared with user yet first, then create relationship for this descendants ?

class CreateFolderShareAuthorities < ActiveRecord::Migration[5.0]      .......      add_index :folder_share_authorities, [:folder_id, :user_id], unique: true  end  

p/s: descendants of a folder can be query by just folder.descendants command (from ancestry gem)

rails: how to filter a response/request json parameters when logging done by a gem?

Posted: 28 Oct 2016 07:31 AM PDT

In a rails application I am using gem called active_shipping

this gem logs API response/request internally. Problem begins when I save the logs to file system with passwords I pass on request... (rails doesn't filter by the regular filter mechanism)

Anyway filtering this json request logs?

Thanks

Rails Paperclip to Carrierwave - Carrierwave trying to process images on request

Posted: 28 Oct 2016 07:30 AM PDT

I have some images on amazon s3. A rails app was accessing them through paperclip. I've migrated to carrierwave.

For some reason, using something like:

version :medium, :if => :image? do    process resize_to_fit: [600, 10000]  end  

in the carrierwave Uploader is making carrierwave attempt to (I think, I can't see anything in the logs) process these images when requesting them, which is obviously not ideal as it's taking minutes to display an image. f I remove the processing from the Uploader, then they're loading instantly, as they should.

Why is this happening? The Uploader should only process new images that are being uploaded, am I correct? What on earth is it trying to do...

ember not communicating with rails

Posted: 28 Oct 2016 08:34 AM PDT

I am following the tutorial at Ember and Rails 5 with JSON API: A Modern Bridge.

Thus, I now have a rails-api for backend and ember for front end. I started the rails server as suggested:

$ bin/rails server --binding 0.0.0.0

Started the ember server:

$ Ember s --proxy --http ://localhost:8080 --port 8081

I had to specify a port for creating the Ember server though, because I got an error saying:

Port 8080 is already in use

It seems as the rails backend work as if it is suppose to. When I visited http://localhost/something.json I get the proper json response.

In the tutorial they ask you to visit the ember frontend open ember inspector, console and enter the command :

$E.store.findAll('book');

The response I get is:

Uncaught TypeError: Cannot read property 'findAll' of undefined(…)

I am using c9 with this tutorial, not sure if it has anything to do with it though.

The question is, Why am I getting this Error?

I Am new to stackoverflow, Rails and Ember.

I have searched the question and the solutions posted did not work for me.

Capybara with Chrome driver, all specs are crashing with EOFError: end of file reached

Posted: 28 Oct 2016 07:58 AM PDT

Capybara using Chrome driver with setup:

spec_helper

Capybara.register_driver :chrome do |app|    Capybara::Selenium::Driver.new(app, :browser => :chrome)  end  Capybara.javascript_driver = :chrome  

I appear to be getting

 EOFError:     end of file reached  

On all of my Javascript tests when I run them with chrome driver.

Running with poltergeist they work fine.

• also when they crash they appear to open multiple instances of chrome which hang (but do not exit) see http://screencast.com/t/Worwl9d6Iuhr screenshot example

• these appear to affect only my javascript specs (:js => true in Capybara)

• Rebooting my machine did not solve the problem

• Reboot did not help

• My Chrome Mac OS X is currently at 54.0.2840.71

• I'm not sure when sub-sub-point version 71 got released since of course Chrome doesn't tell you or even seem to have it available in some kind of update history. The public information says sub-point version 54.0.2840 was released 2016-10-12 but it doesn't specify when sub-sub-point version 71 was released

• I can reproduce the effect on both my code on master, as well, I have a specific memory of running these specs with Chrome driver earlier in this week, so I am strongly suspecting that Chrome did a sub-sub-point release here and broke this.

if anyone else can confirm I would appreciate it. otherwise, if I find a local problem, I will post answer here.

• Capybara 2.7.1

• selenium-webdriver 2.53.0

• I located the Chromedriver executable in my machine at /usr/local/bin/chromedriver [is this the right one -- I seem to have an older one in /Users/jason/bin/chromedriver ?]

$ which chromedriver /usr/local/bin/chromedriver

$ /usr/local/bin/chromedriver -v ChromeDriver 2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b)

How to add multiple images with ActiveAdmin?

Posted: 28 Oct 2016 07:11 AM PDT

show do |cat|      h3 cat.title      h3 cat.description      div.each do        # image_tag cat.image_url        image_tag(cat.image_url(:thumb))      end    end  

what I am doing wrong?

and my view

<% @subcategory.each do |cat| %>      <div class="block" style="margin-bottom:20px">        <div class="main-title" data-toggle="modal" data-target="#mdf-modal"><%= cat.title %></div>        <p><%= cat.description %></p>          <div class="col-md-3">          <a href="<%= cat.image_url %>" data-lighter>            <%= image_tag(cat.image_url, :alt => "ivm logo") %>            <%= image_tag("zoom.png", :alt => "ivm logo", class: 'zoom') %>          </a>        </div>        <div class="line"></div>      </div>      <% end %>  

Rails Gem for Searching

Posted: 28 Oct 2016 08:32 AM PDT

I have a webapp where I want to provide an advanced search in which the user enters an arbitrary amount of queries joined by AND's and/or OR's, like this:

(entered into the search box on the webpage)

name = "john" OR (occupation = "gardener" AND hobby.main = "reading")  

In a prior post, I successfully implemented a system in which I directly convert queries formatted as above into valid SQL statements, and feed them straight into SQL to query the database.

This worked, but now I worry about three things:

  1. This wreaks of SQL injection
  2. If the user's input is invalid SQL throws an error which isn't very pretty...had some trouble handling these exceptions (though this part is doable).
  3. The code just seems really hacky and I wonder if there's a better way.

Well, I've heard there is a better way, by using search gems.

However, I've been having trouble finding gems that match my needs. Many of the gems seem too complex for what I need, and nothing that I've found made it clear exactly how you could implement specifically what I'm looking for -- where the user enters a dynamic number of queries joined by AND / OR statements.

Exactly how costly is it to just convert the statement straight to SQL syntax and inject it right in, like I'm doing right now? How easy is it to incorporate one of these gems for what I want? What would an "experienced" Rails developer do? I'm a complete noobie to Rails, so I don't have experience with any of this.

Ruby has_many without destroy

Posted: 28 Oct 2016 06:36 AM PDT

I'm facing a model problem. I've 3 models : User, Address and Residence

User:

class User < ActiveRecord::Base    acts_as_paranoid      has_one :address, dependent: :destroy #should be has_many but not current problem    has_many :objects, dependent: :destroy    has_many :residences, dependent: :destroy  end  

Address

class Address < ActiveRecord::Base    acts_as_paranoid      belongs_to :user, inverse_of: :address    belongs_to :residence, inverse_of: :address      validates :user, presence: true  

end

Residence:

class Residence < ActiveRecord::Base    belongs_to :user      has_one :address, through: :user, dependent: :nullify    has_many :objects, through: :user  end  

The problem is when I want to delete a User or a Residence The system failed to delete residence due to a foreign key and the system said to me that cannot be done because still reference to residence in adresses table.

I don't want to delete address linked to Residence when I delete residence, address should only be delete bu user deletion (that's why i try to use nullify without luck.

Need I to use a join table instead of references between residences and addresses?

Thanks

Rails javascript buttons causing post

Posted: 28 Oct 2016 08:18 AM PDT

I've created a form where a user can move items from the left side to the right side using two buttons. After the user has finished adding their items they can name & save the group. At least that's how it's supposed to work. Instead, as soon as I add one item, and click on the 'move right' button the POST action fires. Why are my javascript driven buttons firing the POST action instead of the submit_tag?

Here's what the form looks like view/settings/global.html.erb:

enter image description here

The form code in the view:

<%= form_tag '/create_host_group', id: "host_group_form", class: "form-horizontal" do %>      <%= label_tag "Group Name", nil, required: true, class: "control-label col-md-2 col-sm-2 col-xs-12" %>    <%= text_field_tag 'host_group_name', nil, class: "form-control" %>      <%= label_tag "Available Hosts", nil, class: "control-label col-md-2 col-sm-2 col-xs-12" %>    <select id="hosts_available" class="form-control" size="30" multiple>       <% @network_hosts.each do |n| %>          <option value="<%= n.id %>"><%= n.ip_address %></option>       <% end %>    </select>      <button id="btnRight" class="btn btn-success"><i class="fa fa-2x fa-forward"></i></button>    <br/>    <button id="btnLeft" class="btn btn-danger"><i class="fa fa-2x fa-backward"></i></button>      <select id="hosts_assigned" class="form-control" size="30" multiple></select>      <%= submit_tag "Add Group", class: "btn btn-success" %>  <% end %>    <script>    $("#btnLeft").click(function(){      var selectedItem = $("#hosts_assigned option:selected");      $("#hosts_available").append(selectedItem);    });      $("#btnRight").click(function(){      var selectedItem = $("#hosts_available option:selected");      $("#hosts_assigned").append(selectedItem);    });  </script>  

In my controller for loading the view settings_controller.rb:

class SettingsController < ApplicationController    before_action :get_company_and_locations      def global      get_network_hosts    end    end  

The POST action is calling network_host_groups_controller#create, which I'm just trying to debug right now:

class NetworkHostGroupsController < ApplicationController      def create      group_name = params[:host_group_name]      assigned_hosts = params[:hosts_assigned]      puts "#{group_name}: #{assigned_hosts}"    end    end  

And my routes are:

match '/global_settings', to: 'settings#global', via: 'get'  match '/create_host_group', to: 'network_host_groups#create', via: 'post'  

How to sync activerecord clock with mysql server clock instead of the server clock hosting the app?

Posted: 28 Oct 2016 06:48 AM PDT

Like many of you, we have many (equivalent) servers in production to handle large traffic. For a reason i dont need to explain, our servers are completely closed for the outside world, even for access on ntp ports in order to sync time.

So i need to hack the rails app to get time not from the server hosting it, but from the one hosting our common database, so that timestamps (created_at / updated_at) can stand logic.

Any idea how to do that ?

Rails 5 Pivot Table or alternative approach

Posted: 28 Oct 2016 05:49 AM PDT

My database table STOCKMOVEMENTS

ID, PRODUCT, QUANTITY, REASON

1 | Product1 | 2 | 1

2 | Product2 | 3 | 1

3 | Product1 | -1 | -1

4 | Product2 | -2 | -1

5 | Product2 | 4 | 1

Column reason is the movement type. -1 corresponds to a sale, 1 corresponds to a purchase. Table need to be grouped by product and sum units.

I want to achieve

PRODUCT SOLD PURCHASED

Product1 | 1 | 1 |

Product2 | 2 | 7 |

I understand that this is the case when a pivot table should be used. But I also need to show in table other columns like product.category.NAME (from a join with products table). But looking at the documentation I can't find out how to to it.

Question1 - Should I use a pivot table or use a different approach?

Question 2 - A solution that seems to me logic and simple would be create a scope or a method sold (and purchased) and then call in my table something like:

stockmovement.product.NAME  stockmovement.sold  stockmovement.purchased  

To achieve that I'd need

sum(UNITS) where REASON = 1 as purchased

and

sum(UNITS) where REASON = -1 as sold

But I don't really know how to do it. Mostly for the where clause.

Is something like this possible at all?

If someone could point me in the right direction would be great. Thanks!

ActiveRecord multiple custom length validation

Posted: 28 Oct 2016 06:18 AM PDT

I have an Address model and I need to validate the :zipcode length depending on the :country.

For example:

  • If :country == 'us', maximum :zipcode length should be 5.
  • If :country == 'br', maximum :zipcode length should be 8.

And so on...

I'm running Ruby on Rails 4.2.7.

assets folder(images,stylesheets,javascripts files) is not working properly on the server in ruby on rails

Posted: 28 Oct 2016 06:09 AM PDT

i am new in ruby on rails, i have done some modification in assets file ( like add a new image file default2.png,some style file has be changed and some javascript file also changed).

I have uploaded all file on the server in assets folder then tried to precompile all assets with the help of following command rake assets:precompile and also tried rake assets:precompile RAILS_ENV= production

after that css was not working properly check box is not visible, some images are not displaying in page.

we try to rollback the precompile file using these steps

  1. rm -fr public/assets
  2. rake assets:clean

again we tried the rake assets:precompile and rake assets:precompile RAILS_ENV= production.

Problem is not resolved, i had tried with below links

database configuration does not specify adapter

Rollback rake assets:precompile

rails 4 asset pipeline vendor assets images are not being precompiled

then got error **config.eager_load is set to nil. Please update your config/environments/*.rb fil es accordingly:

  • development - set it to false
  • test - set it to false (unless you use a tool that preloads your test enviro nment)
  • production - set it to true

rake aborted! ActiveRecord::AdapterNotSpecified: '' database is not configured. Available: ["d efault", "development", "staging", "production"] **

Adding custom field to devise User model error

Posted: 28 Oct 2016 07:06 AM PDT

i'm adding a full_name (string) value to my model User, using gem Devise.

# app/controllers/application_controller.rb    class ApplicationController < ActionController::Base    include Authorization    protect_from_forgery with: :exception  end  

And also

# app/controllers/concerns/Authorization.rb    module Authentication    extend ActiveSupport::Concern      private      def devise_parameter_sanitizer      if resource_class == User        User::ParameterSanitizer.new(User, :user, params)      else        super      end      end  end      # app/controllers/sanitizers/user/parameter_sanitizer.rb    class User    class ParameterSanitizer < Devise::ParameterSanitizer      USER_PARAMS = %i(        full_name        email        password        password_confirmation      ).freeze        def sign_up        default_params.permit(USER_PARAMS)      end        def account_update        default_params.permit(USER_PARAMS)      end    end  end  

Everything should work, but I've got an error when creating user
Unpermitted parameter: full_name

Any ideas?

How to get data of last 24 hours on top in rails

Posted: 28 Oct 2016 05:31 AM PDT

There is a model post . Post are created by either PM or User. I want to get all posts in which the posts created by PM in last 24 hours come on top.

I try

posts.sort_by{|t| -t["role_id"] }  

But by this PM all posts on top. I want PM posts of only last 24 hours on top.

Repository not found. Using capistrano and privare repository in team

Posted: 28 Oct 2016 05:16 AM PDT

I have problems using the (deploy key) with capistrano, just after adding my private repositories to a team of github. I leave my setup, any suggestions?

    # Change these  server 'xx.xx.xx.xx', port: 22, roles: [:web, :app, :db], primary: true    set :repo_url,        'git@github.com:Companyname/proyect.git'  set :repository, "git@github.com:Companyname/proyect.git"  set :scm, "git"  set :application,     'xxxxxx'  set :user,            'xxxxxx'  set :puma_threads,    [4, 16]  set :puma_workers,    0  set :rvm_ruby_version, '2.2.1@rails426'  # Don't change these unless you know what you're doing  set :pty,             true  set :use_sudo,        false  set :stage,           :production  set :deploy_via,      :copy  set :deploy_to,       "/home/#{fetch(:user)}/apps/#{fetch(:application)}"  set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"  set :puma_state,      "#{shared_path}/tmp/pids/puma.state"  set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"  set :puma_access_log, "#{release_path}/log/puma.error.log"  set :puma_error_log,  "#{release_path}/log/puma.access.log"  set :ssh_options,     { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub), verbose: :debug }  set :puma_preload_app, true  set :puma_worker_timeout, nil  set :puma_init_active_record, true  # Change to false when not using ActiveRecord  set :default_env, { rvm_bin_path: '~/.rvm/bin' }  set :bundle_flags, "--deployment"    ## Defaults:  # set :scm,           :git  # set :branch,        :master  set :format, :airbrussh  set :log_level,     :debug  # set :keep_releases, 5    ## Linked Files & Directories (Default None):  # set :linked_files, %w{config/database.yml}  # set :linked_dirs,  %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}  set :linked_dirs, %w{tmp/pids tmp/sockets log}  namespace :puma do      .......    # ps aux | grep puma    # Get puma pid  # kill -s SIGUSR2 pid   # Restart puma  # kill -s SIGTERM pid   # Stop puma  

Maybe is a setup in github, but i dont have idea.

How a Rails web service can send informations to an application?

Posted: 28 Oct 2016 05:11 AM PDT

Usually, we use applications to consume web services methods. But in the other case, I mean when we need web services to send informations to our application without the app first contacts the web service. How can we do ?

I have thought to use Ruby Sockets (from my Rails app) to interact with Swift Sockets (of my Cocoa application), but is it the best way to do that ? Or perhaps there is another way that is more neat ?

How to patch rails built in model generators?

Posted: 28 Oct 2016 05:39 AM PDT

I'm in the situation where I want to add another field to every model that I create with rails generate model MyModel. By default it will get assigned an ID as well as timestamps for created_at and updated_at.

How can I reopen this generator and add a field deleted_at to the default generator?

Radio buttons in rails not taking default value based on the data stored in the database

Posted: 28 Oct 2016 04:47 AM PDT

Am trying to create a profile page where the user can check "male" or "female". After saving the form, whenever the user visits the page again, the gender must be set by default based on the data stored in the database.

Am using the form_for helper here.

<%= form_for @profile do |f| %>    <%= f.label :gender, "Male", :value => "m" do %>      <%= f.radio_button :gender, "m" %>    <% end %>    <%= f.label :gender, "Female", :value => "f" do %>      <%= f.radio_button :gender, "f" %>    <% end %>  <% end %>  

how can I set one column in database when one user sign_out with devise

Posted: 28 Oct 2016 04:50 AM PDT

I set one column called if_login in one table called users. When I execute sign_in path, I use the method user_sign_in? to set the column if_login value to 1. And how can I modify the codes in devise to set the column if_login to 0?

here is when excute 'sign_in' path ,the method will set the user's 'if_login' value=1
if user_signed_in?      @user.update(if_login:1)  end  @user.save  

Footer Causing a second Page to appear

Posted: 28 Oct 2016 04:04 AM PDT

I'm working on a project that uses wicked_pdf, I have a footer partial which I reference in the pdf generation with:

  format.pdf do       render :pdf => "document",              :margin => {top: 0, right: 0, bottom: 20, left: 0},              :footer => {                :html => {                  :template => "/document/_footer"                }              }    end  

For some reason when I have the footer there it causes an extra page to appear on the invoice. So a one page document has a second blank page with a footer

create relationships for STI child

Posted: 28 Oct 2016 05:17 AM PDT

I have User, Teacher and ClassRomm model using STI as following

class User < ApplicationRecord  end    class Teacher < User    has_many :class_rooms  end    class Student < User    has_many_and_belongs_to :class_rooms  end    class ClassRoom < ApplicationRecord    belongs_to :teachers    has_many_and_belongs_to :students  end  

my question how can i create migration for all relationships between user,teacher,Student and classRooms ?

for example should class_rooms has forignKey column for instructor_id or user_id

Rails 5, Added action controller don't render correctly

Posted: 28 Oct 2016 03:05 AM PDT

I've added two new actions at my controller users

def show  end    def setting  end    def myhome  end  

and the route in route.rb

resources :users do     collection do        get 'myhome'     end     member do        get 'setting     end  end  

Also in users views i've added the pages 'setting.html.erb' and 'myhome.html.erb'

Now, if i browse '/users/1/setting' i see the correct page, but if i browse 'users/myhome' i see the show.html.erb page.

Really i don't understand.

jQuery hover: does not work for each instance of ".map"

Posted: 28 Oct 2016 02:57 AM PDT

So in my index view i have this (shortened to show the important part)

<% @tutor.map do |tutor| %>    <%= image_tag(asset_url('question-mark.png'), class: 'hoverIcon', size:'16x16') %>    <div id='hoverRating' style='display: none;'>      <p>        The Rating is ...       </p>    </div>  <% end %>  

And here's the script

$('.hoverIcon').hover(    function () {      $('#hoverRating').show();    },    function () {      $('#hoverRating').hide();    }  );  

So the problem i have is that on the first instance of the image, the hover function works perfectly fine, but when i go onto the second instance of the image and i hover over it, the #hoverRating appears over the first instance of the image instead.

How do i make it such that for each instance of the image, the #hoverRating that appears is over that particular image that is being hovered over instead?

No comments:

Post a Comment