ruby-on-rails

class methods/array in activerecord

I want to create a list from a class' attributes I'm new with ruby- i have an activerecord class called fixture and what an array of "Home Team", "Draw", "Away team", where home team and away team are both fields in the Fixture table I have come up with the following code sticking it in the Fixture class- how do access the values of th...

Validation error messages

Hi, I have two models, frontend and user with respective controllers and views. From a form_for in frontend view I'm calling a create method in user controller and I save new user in database. All works. The problem comes with validation. If something is wrong with the model validators I need error messages to be displayed on frontend...

Pointers for a C# Developer Learning Ruby on Rails

I've spent the majority of my professional career developing in C#. To broaden my abilities I've recently begun learning Ruby on Rails. Thus far I've found scaffolding a basic CRUD app in RoR to be easy and fun. I am well aware that I have barely scratched the surface of what RoR is capable of but am curious if there is anything I should...

How do you pass a method with arguments to #to_xml?

How can I pass a method with an argument to #to_xml? @object.to_xml(:methods => [:a_method_with_args] ) Is there a way to do this? What is the correct syntax? Thanks. ...

edit content in ruby on rails shopping cart

I am trying to build a simple shopping cart with rails, now I am able to add products to cart, I want to know how can I edit products while they are in cart, I am using sessions to control the products in shopping cart. here is what the user see when add to cart : <% @cart.items.each do |item| %> <tr> <td> <%= image_tag item...

Rails Associations

I can't seem to wrap my mind around Rails associations. Let's say I have 3 tables. One for Users, one for Recipes, and one for Ingredients. Here's an example of the database (in yaml): Users: id: 1 email: funnyusername password: pass1234 Recipes: id: 1591 user_id: 1 name: Pizza Dough Ingredients: id: 1 name: Flour i...

Rails plugin for US states and cities

Hello Friends, We need a Rails plugin for US states and cities. Please see if we can get that. ...

Weird "406 not acceptable" error

When I try to hit this action via Javascript, I get a 406 Not Acceptable error: def show @annotation = Annotation.find_by_id(params[:id]) respond_to do |format| format.html { if @annotation.blank? redirect_to root_path else redirect_to inline_annotation_path(@annotation) ...

Installing Rails Plugin Requires Git?

Installing rails plugins from github requires git in the system? OS is linux. Is it possible to install plugin without git installation in the local system. ...

How much do you test your controllers?

I am currently beginning with BDD - I have not written any tests before. I always try to keep my models fat and my controllers skinny. What do you think - are controller specs necessary? Best regards ...

how make user profile pages accesses through myside.com/USER_ID in rails

Hello, I'm using Rails and I have a User Controller for creating new users. To view current users I have to type something like: mysite.com/users/USER_ID I want to change to: mysite.com/USER_ID What is the best way to acheive that? Thanks, Tam ...

Thinking Sphinx: Missing Attribute for Foreign Key

Hi, I know a very, very similar question has been asked before. The hackish solution to that question doesn't work if I want to chain in more scopes, so I'm asking again here, with a bit more information as to where the issue is coming from. # Relevant code only... class Publication < ActiveRecord::Base has_many :issues has_many :a...

Best way to count words in a string in Ruby?

Is there anything better than string.scan(/(\w|-)+/).size (the - is so, e.g., "one-way street" counts as 2 words instead of 3)? ...

Weird time inconsistencies between production and development

For some reason times are appearing differently in development (my local Mac) and production (Heroku). Take a look: (Just prior to doing this I did a heroku db:pull, so the databases should be identical) Production (Heroku) >> Annotation.last.id => 2028 >> Annotation.last.created_at => Sat, 12 Sep 2009 06:51:33 UTC +00:00 >> Time.zone ...

One to Many Query with Joins

I have a book model and a tag model and a join model. The book model has many tags through the join model. How do find books that have both tag 'A' AND tag 'B'? This works for Just A: Book.all(:joins => 'tags', :conditions => {'tags.name' => 'A'}) This works for A or B (or seems to): Book.all(:joins => 'tags', :conditions => {'tags...

link_to_remote in Rails renders incorrect URL when rendered from RJS

I have a partial for a "guest" object which renders a link to a destroy action like this: <%= link_to_remote "remove", :url => { :action => "destroy", :id => guest.id } %> When called from an ERB view it works fine, e.g. <div id="guests"> <%= render :partial => @event.guests %> That is, it renders something like: <a href="#"...

Regex - find all links in a tweet

Hi, My regex is poor and letting me down so some help would be great here. All I want to do is return all the links which appear in a tweet (just a string) - Some examples are: "Great summary http://mytest.com/blog/post.html (#test) "http://mytest.com/blog/post.html (#test) "post: http://mytest.com/blog/post.html" It should also s...

Integrating WordPress Authorization/User Sign-On w/ a Ruby on Rails App

We have an existing WordPress install with a thriving user base. There are also some new Web applications being built in Rails to cover some new functionality. Any suggestions or tips on integrating sign-on between WP and a Rails app? Anyone done anything like this before? ...

Rails: I update migratation file then run db:migrate, but my schema isn't updating.

Im trying to add an extra field to one of my tables. Ive added the field in the migration file (under db\migrate) then ran 'rake db:migrate' which ran without troubles and my text editor even told me my schema.db file has been updated and needs to refresh. The schema file does not contain my new field and any attempts to reference the ...

SQL query to get "vote score"

My votes table looks like this: id: integer vote: boolean voteable_id: integer voteable_type: string voter_id: integer voter_type: string The vote column determines whether the row represents an "up vote" (vote = true) or a "down vote" (vote = false). voteable_type is the class of the thing being voted on, voteable_id is the id of th...