ruby-on-rails

Ruby on Rails prevent nil error when it is assumed record may not exist

I am building a simple book check out application. One of the things that I need to do is determine if a book is checked out. I have my associations between my people and book classes setup through a book_check_out class. My goal is to use the checked_out property of book to determine if a book is presently checked out. However, in my pr...

Controller for the Front Page?

I'm new to Ruby on Rails and I'm sure this question is pretty stupid, but I can't deduce the answer from the examples I've seen, perhaps I haven't seen many good ones. A website I am working on will have 'boxes' (i.e. widgets) in one side bar that will contain dynamic content, and it will also have links on the other sidebar to sections...

Customizing map.resources in Rails

Suppose I have a Book model, which contains many Page models. The routing for this would be as so: map.resources :books do |book| book.resources :pages end Following the Rails default on this quickly leads to problems. Suppose Book #1 has 10 pages. The first Page in Book #2 will have this route: /books/2/pages/11 This is a pre...

Passing instance variable from one form to the a different controller's action in Rails

Hi, Simple question - I have a form where I create an instance of an object. After I create that object (aka submit the form), I want to redirect to a new form that is associated with a different controller's action and carry that instance variable to populate some of that form's fields. I know I typically have 2 options, store that in...

How to rapidly build a Web Application?

To build a Web Application, what kind of open source web application frameworks / technologies are currently present that would be: Faster to learn. Ease of use. Have widgets for rapid development(From a GUI perspective). Database integration. I would want this web app to communicate to a Java client. I am not bound to Java ...

Is there any gem that can help Activerecord Association attributes mapping ?

The gem can help like this : class Book belongs_to :author end book = Book.first book.author_name #=> same as book.author.name book.provide( :author_name, :title ) #=> will automatically map like this: { :title => book.title, :author_name => book.author.name } Is there any gem help ?? Thanks! ...

How long do objects stored in Rails' sessions persist?

If I do session[:greeting] = "Hi!" in one controller action, for how long will I be able to refer to session[:greeting] in other controller actions? Until the user closes his browser? Until a certain amount of time passes? Also, how can I configure this value? ...

Tutorial/Suggestions on YUI with Ruby on Rails

I'm looking at using YUI in my Ruby on Rails application. What is the best tutorial, examples, or how-tos about generally integrating YUI into my Rails app. Thanks in advance! ...

What to do when find doesn't find any records in Ruby on Rails

I am trying to accomplish the atypical library learning a language application. I have been able to create Books, People, and BookCheckOuts. I've got the relationships working pretty well but am having issues with wrapping my head around how to handle books that have never been checked out. I've created two properties on my book class C...

Ruby on Rails Has Many Through Array Problem

Hi all, I'm having problems adding to a Has Many Through association using user_ids. My communication model looks like this: class communication has_many :recipients has_many :users, :through => :recipients end In my create action for the communication controller I am trying to manually add user_ids to the communication object lik...

Form Action garbled, Rails 2.3.3

I seem to have a problem that I can't find the solution for myself, I hope someone can help. I have a form defined like so: <% form_for @leads do |f| %> I have a resource called @leads (map.resource :leads) But when I look in the HTML code of the page it generates, I see as a form action the following <form action="/lead.%23%3Clea...

Rails Models counter_cache column initialization

I'm using rspec for testing and hornsby scenarios for object graphs used in tests. Is it good practice to initialize counter cache columns to 0 value instead of leaving them uninitialized (nil)? Or should i define default value in migrations that create those counter cache columns? ...

Named Scope Problem With "Has Many Through" Association

I'm using named scopes to process some filtering actions, and the log is showing that everything is working perfectly, except that after the app goes and finds the correct data, it then ignores what it found and just lists a find.all instead of the filtered result. Here's the details. I have 3 models: Users, Markets and Schedules. U...

Querying with conditions in Rails

Assume, we have two tables: "Items" and "Types". The relationships are: item belongs_to type type has_many items Also, the Item table have a column, let's call it "mark". What would be a query (in a Rails secure way if it's possible) to extract all the types from them Types table, wich have connected items in Items table with a "mark"...

Ruby On Rails: using arrays with link_to

Hello, I was curious on how to use arrays in the link_to method in ruby on rails for example: Controller: def index @test = [1,2,3] end View: <%= link_to "test", {:action => 'index'}, :test => @test %> When looking at the source then, I end up with something to the effect of: <a href="/index/" test="123">test</a> My guess ...

What are the performance implications of adding all JQuery code to application.js in a Rails project

I'm running a fairly large web application which contains an increasing amount of JQuery code for both UI polish and making AJAX requests. Larger chunks of code live in their own, dedicated .js file, but there are an increasing number of pages (primarily forms) which use a small sprinkling of JQuery for showing/hiding form elements, mod...

How do you configure the template used by ActionMailer?

When using ActionMailer it uses a 'view' in the conventional path but how do you configure the 'view' that is being used (i.e. choose your own)? It looks easy enough to change the 'layout' being used but where you do the same for the view? ...

Where should I place code which generates Excel spreadsheet?

I am using spreadsheet gem to generate native Excel file. This is not CSV, XML file. Ordinary Ruby code is used to create the file. The generated Excel file (kept in StringIO) is forwarded to a client using send_data method. I need send_data method because of its parameters like disposition. The data for the Excel is retrieved in contro...

Using RoR with a legacy table that uses E-A-V

I'm needing to connect to a legacy database and pull a subset of data from a table that uses the entity-attribute-value model to store a contact's information. The table looks like the following: subscriberid fieldid data 1 2 Jack 1 3 Sparrow 2 2 Dan 2 ...

Rails Basics: Where's My Installation, Sources, API, Online Sources

I'm trying to run this method which should work according to this: ActiveSupport::TimeZone.new("whatever",3600) but this initializer doesn't exist. So I would like to look at the sources for my Rails version (2.3.4) to see if it's private or if I'm missing the point completely (the one-argument constructor works). And suddenly I re...