ruby-on-rails

Working with nested information in controller/views

This is a beginner's question but for some reason I cannot find the answer elsewhere. Customer has_many orders Order has_many order_items I am in customer/show.html.erb and I want my customer to manipulate order_items. Many orders have many order_items and I want to search ALL of those order_items to find those such that read == fa...

How to execute complex Arel query in Rails 3 from Model

Hi there, I'm on Rails 3,and I have a SQL query composed of a few joins that I've built up in Arel. I want to run this query from a method in one of my models, but I'm not sure of how to do this. The arel object turns out to be of type Arel::InnerJoin, and I want to retrieve an array of all objects returned from that query. Do I run Mod...

ubuntu ruby on rails installation

hi, all I installed RoR on ubuntu 10, using all kinds so method i could find on internet, either "sudo apt-get" or "sudo gem install", by running 'gem list', i can see they are all the latest version: *** LOCAL GEMS *** actionmailer (2.3.8) actionpack (2.3.8) activerecord (2.3.8) activeresource (2.3.8) activesupport (2.3.8) fastthre...

remove charset from content type

I have a old-stupid service making request to my app that fails when the Content-Type include the charset line Content-Type text/html; charset=utf-8 and I don't know how to remove it from my rails response. Every time that I override the headers forcing just the first part (Content-Type text/html) Rails adds the charset to the head...

ruby on rails Controller class instantiate a ruby class?

Hi I am new to RoR .I want my controller to instatiate an existing class from lib . Collect data in the form of a string and throw the result on the view.erb.Can I do that. Do i have to create a new model object and that should that model object inturn call the lib class. ...

What's the Rails 3 replacement for ActiveRecord::Errors?

What's the Rails 3 replacement for ActiveRecord::Errors? In Rails 2.3.8, this is an object: >> ActiveRecord::Errors => ActiveRecord::Errors In Rails 3.0.0rc, you get a NameError: >> ActiveRecord::Errors NameError: uninitialized constant ActiveRecord::Errors from (irb):2 I'm trying to make the wizardly generator work with Rails 3....

how to interacts with database in ruby

i installed rails on ruby and i have mysql as a database installed now how i interacts with datbase uisng rails ,will i have to install mysql gems for ruby or what first step i have to do. in tutorials its written like that creates your rails applicationl like rails appname cd to appname rails appname -d mysql will it be enough to s...

Models or migrations first in Rails?

I wonder, should I create models or migrations first in Rails? I've been following BDD, testing first, then actual code. That has given me an insight of going from TOP to BOTTOM. I have heard some people say: first models and their associations, then migrations to create the database for them. Migrations/tables adapt to models, not the...

How to access ':has_many :though' join table data when using to_json?

Hi folks, I have three models (simplified here): class Child < ActiveRecord::Base has_many :childviews, :dependent => :nullify has_many :observations, :through => :childviews end class Childview < ActiveRecord::Base belongs_to :observation belongs_to :child end class Observation < ActiveRecord::Base has_many :chi...

How to test a before_save method including accossioations with rspec

Hi there, I'm having a problem testing the following model: class Bill < ActiveRecord::Base belongs_to :consignee before_save :calc_rate def calc_rate self.chargeableweight = self.consignee.destination.rate * self.weight end end The consignee model: class Consignee < ActiveRecord::Base belongs_to :destination has_ma...

two association belongs_to with the same models

I have two classes : User, Patent and Help (belongs_to :user and belongs_to :patent) When I click to a link I must create an "Help" that refer to the patent and also to the users. One user is the helper and the other one is the caller. patents_controller: def create @patent = Patent.find(params[:patent_id]) @patent.help...

How do i test routes in Rails 3 plugins?

I've tried to use the recommended way (from the Rails Guides) to test routes generated in plugins, but the test keeps failing. What's odd is that if I reload the routes AFTER creating the route (or so I think), the test fails, but if I let the test go through once (e.g. using autotest), then the route gets recognized on subsequent attem...

rails [template + partial] results in repeated output!

What on earth? In posts/_post_brief.html.haml: - title link_to "#{post_brief.title} by #{post_brief.user.full_name}", post_brief - content_for :info do - if post_brief.tags.count > 0 Tags: #{post_brief.tags.collect {|t| t.name}.join(", ")} - content_for :post_body do =post_brief.message In posts/_post_wrapper.html.h...

Dojox Grid pass two fields to formatter

Hello, I created a dojox.Grid successfully, but in one case I need to pass two fields to a formatter function instead of just one. For instance: { field: 'id', name: 'Id', formatter: formatterFunction, }, I need to pass to formatterFunction() both 'id' and 'name' for instance. How can I do this? Thank you...

Rails Devise send password reset mail as delayed job

i want set the rails plugin devise'reset_password_instructions to delayed_job..but i tried many ways is fail. i found a function password_controller#creat they have self.resource = resource_class.send_reset_password_instructions(params[resource_name]) i think the sentence used for send email to reset password. i want alter it like ...

Paperclip Amazon S3 setup with Heroku

has_attached_file :image, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => "/:style/:filename" What is this :path => "/:style/:filename"` I also want to to include the style for this attached image, is that what the :path is? the style I want is this: :styles => { :medium => "275x275>", :thumb => "175x155>" }...

Rails response.format fallback?

A rails app has some files end with .mobile.erb, which is for iPhone. There is before_filter which set request.format = :mobile by check the request.user_agent. My question is below: If some_action.mobile.erb doesn't exist. How to fallback to some_action.html.erb rather than an error page. ...

what is the Best OS for Ruby on rails and Java Development?

HI I am studying computer applications (software development) and will graduate in a year, i will be taking a year off to get my coding skills up to scratch as i have recently come to love code and development. i tried getting rails working on my windows 7 machine but that was painful. My question is, is it worth it to go out and bu...

rails facebooker vs facebook js sdk

I am exploring facebook integration with my rails app and wondering what is the best practice for rails applications. 1 - Is js sdk the better route or the facebooker gem? I would like to allow users to login via facebook, post content/links to their walls, see friend activity in the application, invite fb friends, from the rails app et...

Rails - How should one organize their model code?

Hello, I'm sorry if this seems over simplified but I'm wondering quite specifically what the general consensus is on how model code should be organized. Association declarations, if you think certain association types should be declared before others, accepts_nested_resource declarations, validations, custom validations, protected and p...