ruby-on-rails

Suggestions on making multi-language web site.

I am writing a site with more than one language, is there any easy way or technique to reduct the workload of changing which text to another language.I have an idea, but I don't know whether it is suitable or easy enough. I create a XML that contain all the text in my web, when the user change their language, my program will base on the ...

Best online (free) resources for learning Ruby on Rails?

It seems like there's a lot of cool stuff going on in the Ruby on Rails world. I am primarily a PHP developer, and use Zend Framework for creating web applications, but I would like to learn more about Ruby on Rails. Where can I find the best online resources for learning Ruby on Rails? Resources: Here are some of the resources I've c...

Newbie stuck again.. No errors, but my data won't save

http://stackoverflow.com/questions/1993615/hasmany-build-method-rails Was my last question. It now works: no errors. The new problem is that the new unit conversion doesn't associate with an ingredient ID. I thought this was "just supposed to work" from the build method? Unit Conversion controller: def new @ingredient = Ingredient...

One to many relationship in ROR using Formtastic

following up with this topic: http://stackoverflow.com/questions/1992094/one-to-many-relationship-in-ror I am creating a category that may have many products. So, I use the Formtastic as user Chandra Patni suggested. But I find there is a problem when I added attr_accessible to the product.rb. class Product < ActiveRecord::Base valid...

How to keep GET requests from deleting in Rails

Rails is supposed to magically see that a request is a "DELETE" versus "GET" request, right? I can hit http://localhost/controller/destroy/1 and it'll delete the record. How do developers typically prevent such silly deleting? ...

how to update twitter in rails

def post_to_twitter message = from some where url = URI.parse('http://twitter.com/statuses/update.xml') req = Net::HTTP::Post.new(url.path) req.basic_auth 'account', 'password' req.set_form_data({'status' => message}) res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } case res when Net::HTTPSuccess, Net::HTTPRedire...

uninitialized constant Active Scaffold rails 2.3.5

Hi guy, I update my rails application 2.0.2 to 2.3.5. I use active scaffold for the administration part. I change nothing in my code but a problem is coming with the update. I have a controller 'admin/user_controller' to manage users. Here is the code of the controller: class Admin::UserController < ApplicationController layou...

create a many to many relationship in rails

Users can vote on posts, so I set a many to many relationship in rails: users have many votes posts have many votes posts have many users through votes users have many posts through votes Is there a more elegant way to create a new vote than this: user.votes.create(:post_id => post.id).save ? thanks ...

Rails: Why does the model method not work?

Hi, its the first time I post here. I have a problem that i can somehow not solve. Just for the record, I know what instance and class methods are (even if I may not understand them completely ;-) Here is my model code: class Car < ActiveRecord::Base has_many :drives has_many :users, :through => :drives def self.user_ids() ids = [] ...

unable to deploy using Capistrano

I've been struggling on this rails app for the past week and a half – any help would be appreciated. Im running from a windows machine [vista]..using: latest rails to date [jan 2. 2010], capistrano 2.5.10, subversive plugin, TortoiseSVN I've so far:- created the remote repository, created ssh keys, edited the TortoiseSVN config file. N...

Count records returned in a search - ROR

I'm trying to get Rails to return a count of the records returned in a search (search results found); I can get Rails to count the total amount of records using Inventory.count However when I enter @advsearch.count it blows up. Any ideas? The code below is my controller: def new @advsearch = Advsearch.new end def creat...

rails paperclip and passenger `is not recognized by the 'identify' command`

When I upload a photo, my model fails validation, err well even without any validations I'm returned this error: /tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command. and /tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command. I'm confident this is not related to ImageMagick becau...

rails, `flash[:notice]` in my model?

I have a user model in which I have a method for seeing if the user has earned a "badge" def check_if_badges_earned(user) if user.recipes.count > 10 award_badge(1) end If they have earned a badge, the the award_badge method runs and gives the user the associated badge. Can I do something like this? def check_if_badges_earned(user...

not able to display acts_as_taggable_on tags on ruby on rails (and formtastic!)

Given As the User, I am at a nested new vendors/5/reviews/new. In addition to :params that will get written to the Review model, I need to be able to include tags that belong to the Vendor model. I have used acts_as_taggable_on (http://github.com/mbleigh/acts-as-taggable-on): class Vendor.... acts_as_taggable_on :tags, :competito...

Rails XML API design practices

I'm building an XML-based webservice in Rails to serve as the backend for an iPhone app, and I'm wondering how I can best achieve an auth scheme that will let me use both GET and POST requests -- i.e. one that doesn't require auth sent in the body of an XML payload. The wrinkle here is that I'm not using regular HTTP auth. Instead, I'm...

Writing a spec for helper with Ruby on Rails and RSpec

I have been writing specs for controllers and models, but I have never written a helper spec. I have no idea where I start. I have the following snippet in application_helper.rb def title(page_title) content_for(:title) { page_title } end How should I write a helper spec on the code? Also if there's any open-source Rails app...

Generate n unique random integers in ruby / rails

Im trying to generate n unique random numbers between 1 and max I tried the following code but doesn't work (returns repeated numbers) r = [ ] n.times { v = rand(max) while r.include? v ; r << v} Whats wrong with it? Thanks added: max is thousands n is 10 ...

Ruby Console Help with a One-to-Many Association

Hello I've set up a One-to-Many Association between "orders" and "users". I'm wondering how to have console just return an array containing ID's rather than a full array of data: user = User.find_by_login("Lesa") user.orders => [#, #] user.orders.id NoMethodError: undefined method `order' for #<User:0x...

What exactly does save/save! do?

I've noticed that a common error check line in rails is: if @user.save! rather than something like Save If Save is successful Blah Else Blah End So my understanding of "if @user.save!" is that it both saves the object and returns true/false if it was successful. If I call it later on, such as: @user.save! if @user.save! blah ...

Decreasing font size in rails

Im trying to achieve the following effect in rails: If the text is bigger than x characters then make it smaller, the next x characters smaller, the next character smaller, ad infinitum for example x = 7 would output the following html Lorem i<small>psum do<small>lor sit<small> amet, <small>consecte <small>tur adip<small>isicing</smal...