Questions tagged "ruby-on-rails-3" (page No.1)

Rails - first_or_create adding duplicate records?

I have some seeds in my rails app that I am trying to get to grips with. I'll start with the code in question: make = Make.where(value: 'Alfa Romeo').first_or_create model = make.models.where(value: '147').first_or_create trim = model.trims.where(value: '1.6 TS 3d (2001 - 2005)').first_or_create values = [ {value: '2001 (X)'}, {value: '2001 (Y)'}, {value: '2001 (51)'}, ...

Act_as_taggable_on While Searching Database for Keyword

This is using Ruby on Rails 3.1 and Act-as-taggable-on 2.3.1. Basically, I am searching the database for items with a key word such as the following line. @collection_array_keyword = Collection.find_with_index(params[:q]) However, I also want to limit the objects returned to ones that are also have a certain tag. Here ...

Remove cookies cross domain

I've set 2 applicationa. Rails application and Rack one (Grape). I also configured the cookies so it'll be shared cross them. The Rails application is the a client application and the Rack one is for api. In the Rails app I set devise for authentication and in the api the ...

Rails Assign Class And Computed Class To HTML Element

This is driving me nuts, I don't see why something so simple is so difficult to do in Rails. Ok, so I'm looping with an index and attempting to assign individual divs with multiple classes, one is unchanging, but the other gets computed by the loop, i.e., class="item item_1" ... class="item ...

Rails 3 - Rescuing a Mysql2::Error: Table doesn't exist

I have an iteration in which I am calling set_table_name for some model. The idea is that in each iteration, the model changes its table. Sometimes, the table won't exist, in that case, an error of this kind will happen: Mysql2::Error: Table 'db_name.table_name_xyz' doesn't exist I want the iteration to keep running ...

Why does bundle install not use the version of bundler in Gemfile though its available?

When I do a bundle install --path vendor/bundle on my app, I get the following error. Bundler could not find compatible versions for gem "bundler": In Gemfile: bundler (= 1.0.18) java Current Bundler version: bundler (1.1.5) This Gemfile requires a different version of Bundler. Perhaps you need ...

How to make this rails method - windows compatible?

I've grabbed the latest code base of a gem called socialstream but I'm noticing an issue with file uploads on windows machines. The issue seems to be with the code below... # Monkey patches to Ruby on Rails # # Use unix file util to prove the content type sent by the ...

Rails routing top level route and information architecture

I'm looking for some feedback on both the philosophy and technical practice of using a top level route that is not a catch-all in Rails. Example: # routes.rb get '/cities' => 'cities#index' get '/:city_id' => 'cities#show', as: :city, city_id:/([a-z\-\d]+)/ I have about 30k cities that :city_id should be limited to matching things like "/los-angeles" but ...

paper trail plugin and rspec

I have a model car When I update the car object through a form in my application, paper trail plugin is called and a new version is created. But if I test this thing using rspec, paper trail plugin is never called. Any idea why is paper_trail not being called ...

Ruby-RTF Images do not display

We're using the Ruby-RTF gem, found on Github. Essentially, we want to generate a report document that contains the image of a chart, a simple table, and a couple of paragraphs, in a format that the user can use (copy/paste, etc); meaning a PDF wouldn't be an option ...

Prohibit some words from being saved

ruby 1.9.2p290 rails 3.1.1 I have the following routes output: http://localhost:3001/chefs/peter (shows the chef profile **based on username**) http://localhost:3001/chefs/edit (can edit their profile if logged) How to prevent user to create a username that already has a action name like edit? ...

how to overwrite rails engine files that are in the lib directory?

I want to overwrite a file of a rails engine, but that file is in that engine's lib/rails directory. When I take the same file and drop it in my lib/rails directory it doesn't overwrite the file. Seems like rails handles the lib directory differently than say files ...

rails asset pipeline asset group not precompiling datatables

I started building a rails project that uses jquery-datatables-rails. When I put that into my Gemfile I did NOT put it into the assets group. Everything worked fine in development. When I went to put it into production I re-read the documentation and saw that it should ...

Does Geocoder gem work with google API key?

I am using ruby geocoder gem for my project and as the project is growing I am starting to look into connecting to the Google API key. After adding this to the project: Geocoder.configure do |config| # geocoding service (see below for supported options): config.lookup = :google # to use an API key: config.api_key = ...

Like Facebook Fan Page through OpenGraph

Is it possible to like a facebook fan page using only the fanpage's URL with theopengraph api, and koala with rails. Koala provides the following but I have no idea what the number is in the function: @graph.put_like("7204941866_117111188317384") ...

How do i validate fields in the other rails table?

Ok so i have a Contact model class Contact < ActiveRecord::Base has_one :profile validates_presence_of :first_name validates_presence_of :last_name validates_presence_of :email class Profile < ActiveRecord::Base belongs_to :contact And on my form i have fields from that profile and the contact and the validations for the contacts show up ...

Rails 3 how to prevent redirection when POST is done programatically

The controller create method shown below redirects to show method upon successful creation of a customer. I would like this redirection to occur when the post is done from a browser, but the redirection shouldn't happen when I do the post from another program. How do I do that? def create ...

Law of Demeter with one-to-many associations

I'm confused about how to avoid Law of Demeter violations with one-to-many associations. Let's say I have a model like this: class Organization < ActiveRecord::Base has_one :address has_many :employees end I believe that it would be a Law of Demeter violation to do this: organization.address.street_name This could be avoided by having a *address_street_name* ...

« Previous12345678910 ... 14961497Next »Show All