ruby-on-rails

Rails - include and require methods over the modules.

Prawn::Document::Snapshot is a module in the prawn library, so we can include this in our modules. But Prawn::Document::BoundingBox is not a module and it is a class, so how am i suppose to use(include) it in my module? And is inheritance the only way to use that class? ...

find_all_by in <select> table for a certain field in database

Hi, I have a function where I want to show the corresponding value in a select form based on the function below : def index @initval = Haus.find_all_by_haus_id(1) end It will return a list of value that has haus_id = "1" (so e.g. I will get a, b, c) in index.rhtml, I want to show the list corresponding to haus_id="1", but sh...

How to test if correct layout was used in controller using RSpec and Rails 3

I want to write a rspec test that tests if correct layout is used for controller. (Actually I want to test that no layout is used :) ). I did some googling and also Looked here http://stackoverflow.com/questions/109284/testing-rendering-of-a-given-layout-with-rspec-rails But all of this does not work for Rails3. I have used: controll...

Rails: Keeping all the ActiveRecord "validates" lines in a separate file?

A couple of my model classes are getting a little cluttered with all these "validates" calls, so I thought I'd be able to move them into a separate class and 'require' that, but it doesn't seem to work. class Auction < ActiveRecord::Base require 'auction/validations' ... class Auction::Validations include ActiveModel::Validations...

How to tell bundler to use installed mswin32 version of a gem?

I did the: gem install hpricot --platform=mswin32 It's correctly listed when I do gem list: *** LOCAL GEMS *** abstract (1.0.0) actionmailer (3.0.0) actionpack (3.0.0) activemodel (3.0.0) activerecord (3.0.0) activeresource (3.0.0) activesupport (3.0.0) arel (1.0.1) builder (2.1.2) bundler (1.0.0) columnize (0.3.1) erubis (2.6.6) hp...

rails to create and access mysql variable

How to use rails to do this? mysql> SET @t1=1, @t2=2, @t3:=4; mysql> SELECT @t1, @t2, @t3, @t4 := @t1+@t2+@t3; ...

How Can I Access Rails' Session In My Java App

Hi Guys, I have two web apps in one domain. One is written by ruby another is by java. And my rails app is using db session. So there have a "sessions" table in my database. What I want to do is reading the session info from this table in java. Here is my problem: Rails' sessions table is encrypted. So I can not read it directly from J...

Development environment query on some models very slow

Hi there, I am scratching my head over for this issue for last few weeks. My local rails dev environment has been so slow for some reasons. I have production environment working as quick as a bullet on the servers. But with the same code, my dev environment is taking so slow and I have decided to dig into that further. I have found ...

how to define default selected value in select form page

Hi, I have an index.rhtml with this code <select id="subtable" name="subtable" size="20" style="width: 400px"> <% for haus in @hauses %> <option selected value="<%= haus.id %>"><%= haus.timebuild%></option> <% end %> </select> It will show me a list of drop down files in a select box. However, everytime I re...

Passing variable value form js function to rails view (dynamic select)

Hi, I'm using Ryan's solution to add and remove nested model fields dynamically through JavaScript using jQuery. There are 4 models: client, c_person; project, p_person. And one-to-many associations: client has many c_people and project has many p_people (these are people from client side but they belongs to project). Hope it isn't to...

select certain days

I want to build a select tag with only specific days for example Mon ... Fri, how can I generate that in rails 2 ? ...

Rails & FreeagentCentral API Usage

Hi Everyone, I have a rails application that uses the FreeagentCentral API to create new projects in FreeagentCentral when a new case is created in my application. Once the case has been created, I link to the created project in FreeagentCentral using the following link code: <%= link_to "#{image_tag('/images/icons/freeagent.png')} F...

How to generate messagebox on client side

Hii all, In my Ruby code am able to generate messagebox but i would like to know how to see it at client side ,am running rails application means server is running on my machine and tha messagebox is also generating on my machine but am nor able not abble to see it client side anyone has any idea how to do that in ruby?? ...

accepts_nested_attributes_for with belongs_to polymorphic

Hi, I would like set up a polymorphic relation with accepts_nested_attributes_for. Here is the code: class Contact <ActiveRecord::Base has_many :jobs, :as=>:client end class Job <ActiveRecord::Base belongs_to :client, :polymorphic=>:true accepts_nested_attributes_for :client end When I try to access Job.create(..., :client_at...

Trouble connecting Heroku App with Amazon RDS Instance

I'm using Amazon RDS for the first time ever and I've been following the heroku docs to get my app using the RDS instance. So far I've created an instance and I have setup the addon using the format: $ heroku addons:add amazon_rds url=mysql://user:[email protected]/databasename After running heroku rake db:migrate I got ...

Anyone know how to save many objects in one form?

I am trying to save many new objects in a form to one pre-existing parent object. - form_for :parent_object do |f| This is the beginning of my form. And then within it, I would do: - 2.times do - fields_for :child_object do |f| Now if I were to save this, it would render as an ParentObject_Controller Update action which would...

Rails 3 nested forms with has_many :through, entry in join table dosen't get deleted after update

Hi, i have a 'User' model which has a has_many relationship to a 'Number' model through a join table 'user_number' model. I use accepts_nested_attributes_for :numbers, :allow_destroy => true in the 'User' model. Everything works fine except that whenever i delete a number from a user in the edit form, the associated number is deleted ...

Ruby/Rails - Group By performance

I have a collection of Episodes which is connected to a Season and a Show. I need to display them as such: Show title ....Season number 1 ........Episode name ........Episode name ....Season number 2 ........Episode name ........Episode name My controller: def index @show_ids = Following.find_all_by_user_id(curre...

return objects with no associated data

Hi all, class Game < Event has_many :statistics, :dependent => :destroy ... end class Statistic < ActiveRecord::Base belongs_to :game end I want to make a named scope that only returns games that have no statistics. Thanks ...

HTML (or Rails) button code issue

Hi there, I'm struggling with the following problem: What's the correct HTML (and/or Rails) code for a button that resides within a form, and that should lead to a new page, but should not submit anything (from the form)? Basically, the button should work exactly like a hyperlink. Thanks for your help! Tom ...