ruby-on-rails

Rails optmization (with activerecord and view helpers)

Is there a way to do this in Rails: I have an activerecord query @posts = Post.find_by_id(10) Anytime the query is called, SQL is generated and executed at the DB that looks like this SELECT * FROM 'posts' WHERE id = 10 This happens every time the AR query is executed. Similarly with a helper method like this <%= f.textarea :name...

'undefined local variable or method' when trying to use plugin

I am trying to create a plugin and use it in my project. I created a plugin using 'ruby script/generate plugin pluginname' and added the necessary code in the rb file in lib. I added 'require File.dirname(FILE) + '/lib/pluginname' in init.rb file I added the pluginname in my controller where I want to use it..and it throws me an except...

Mapping a polymorphic relationship onto 2 models simultaneously

I need to relate a Comments model with two ids at the same time but can't figure out how. Here' my situation. I am building an on-line school grading system and need to be able let the teacher make a comment on a particular student in a particular course for a particular term (grading period). class Course has_many :course_terms h...

ruby on rails on click events

I am so sorry if this question seems too easy but I can't seem to find it anywhere. I am creating a ruby in steel project. I have created a html.erb and rb file in a vs project (ruby on rails). My problem is the following: In my html1.erb file I have created a text box and button: <p> <input erb:blockvar="erb:f" erb:method="erb::myName...

Help with rails routes

Im having a little trouble setting up routes. I have a 'users' controller/model/views set up restfully so users is set up to be a resource in my routes. I want to change that to be 'usuarios' instead cause the app will be made for spanish speaking region... the reason the user model is in english is cause I was following the authlogic...

Need to know how hash key are handled in ruby

I am working on ruby rails project. I am using Rails 2.3.4 and ruby 1.8.7 . I have a model called User. I have following code in initializer $h = {User => 'I am user' } In the controller I have following code $h[User] First time when I do h[User] I get the right result. However if I refresh the page then I get nil value. I thi...

Rails Gem Install Problems: Google-Geocode

I'm try to install google-geocode for rails sudo gem install google-geocode but I get the following error. Any suggestions? Building native extensions. This could take a while... ERROR: Error installing google-geocode: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/r...

Is Rails hard to understand for a PHP developer?

i know nothing about ruby but a lot about php. when you code in ror...do you actually understand what is going on under the surface if you are a beginner? and do you HAVE TO understand it or is it good enough just to know enough to build something fast? Looking for experiences from people who have made the transition. ...

Rails creating users, roles, and projects

I am still fairly new to rails and activerecord, so please excuse any oversights. I have 3 models that I'm trying to tie together (and a 4th to actually do the tying) to create a permission scheme using user-defined roles. class User < ActiveRecord::Base has_many :user_projects has_many :projects, :through => :user_projects has_m...

Help setting up separate MySQL server for rails

Maybe I am over complicating this in my head but I just don't know what to do next... I have a slice configured with MySQL, Rails & Passenger. I am setting up a new slice to separate the front-end from the database. The current server will become the database server and the new front-end will connect to it. I am using Ubuntu 8.10 on b...

undefined method 'info' for nil:NilClass when running active record migration

I am trying to run an active record migration but am receiving the following error: undefined method 'info' for nil:NilClass Here is the 2 lines of code in my rake task that runs the migration ActiveRecord::Base.establish_connection(YAML::load(File.open('src/SupporterSync.Core/Database/Database.yml'))) ActiveRecord::Migrator.migra...

Starting delayed_job at startup

I'm using delayed_job with capistrano and would like a way to start delayed_job on startup of the web application using the 'script/delayed_job start'. This way capistrano can restart it on deploy. If the server gets rebooted then my delayed_jobs should start up with the project. How can I do this? Should I be looking at doing this in...

Scraping hidden HTML (when visible = false) using Hpricot (Ruby on Rails)

Hi, I've come across an issue which unfortunately I can't seem to surpass, I'm also just a newborn to Ruby on rails unfortunately hence the number of questions I am attempting to scrape a webpage such as the following: http://www.yellowpages.com.mt/Malta/Grocers-Mini-Markets-Retail-In-Malta-Gozo.aspx I would like to scrape The Addres...

Selecting popular models based on count of has_many relationship in Rails

I have two models: Novel has_many :pages Page belongs_to :novel I want to list popular Novels according to page count. Essentially, I want Novel models loaded from the outcome of this query: select p.novel_id, count(*) as count from pages p GROUP BY p.novel_id ORDER BY count DESC I'm sure there's some cute way to do it in Rails 2....

ruby in steel error

I right clicked the project file for my rails project and created a new ruby file. Then i right clicked views and created a new erb file I added a textbox and submit button and click on page (design) and it gives me this error: failed to locate layout file can anyone help me pleasE? thnx ...

How to refresh the dialog box in Facebook after submit (Rails, Facebooker, FBML)?

Hi, I am using Rails (Facebooker). This is for Facebook apps (FBML) and to keep it simple, let's assume it's a student registration system. In my student page (displaying their photo, name, grade etc), I have an 'edit' button. Clicking that button, will display a FB-dialog to edit their details. My aim is simple. I want the user to be...

Ruby on Rails HTTPS Post Bad Request

Greetings all. My application works with a remote server. Server uses https authorization of the certificate. I have following code to authorize and sends request: uri = URI.parse("https://db1-test.content.ertelecom.ru/") http = Net::HTTP.new(uri.host, '443') http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.ca_file...

Rspec, Model load order, fixtures and named_scope challenge

I have some players and the players have a trade state. Rather than hard code trade states like "active" and "inactive" and then have to go looking for strings, I thought I'd be clever and have a separate TradeState model so that a Player has a trade_state_id (a Player can be in only one trade state at a time). Now, it would be a conve...

Ruby on Rails - verify some undefined in model field

Hey! I have users registration procedure on my app. But my users have to register with promo code. So I have model Promocodes for that: t.references :user #this is who have create that promo, e.g. Admin t.string :name #a "name" for promo, e.g. "some_promo" t.integer :allowreg #how much registrations can be done using that promo ...

How could I be sure that choosing HABTM over has_many :through is more suitable?

I have been hearing a lot of buzz around has_many :through(HMT) vs has_and_belongs_to_many (HABTM). This post covers most of its benefits. Okay, HMT sure has some real good benefits over HABTM. However, what I wanted to know that when should I know that I should be using HMT over HABTM? Often I am in a situation where I believe that plai...