ruby-on-rails

Get two random elements from a RoR model

Hi, I'm trying to use RoR for something simple and I'm having some trouble picking up the basics. My closest background is ASP.NET MVC but I'm finding all of the RoR tutorials focus on what rails is really good at (scaffold stuff) but not how to make your own actions and get them to do stuff with parameters etc. (something trivial in A...

Edit form doesn't return selected value

I have a webform created in Rails that asks if someone has children or not? If I submit the form, it's able to get inserted into the db. When I edit the form, it doesn't show it ask selected. For example, the field is <%= f.select :have_children, [ ["Yes", 0"], ["No", 1] ] %> Whenever I select "No" and then edit the form again, it sho...

Ruby on Rails - Scope of Instance Variables with Partial Views

Hello I do not understand how to use instance variable properly with partial views, I am hoping someone here can enlighten me. For example class MainController < ApplicationController def index @item_list = Item.find_all_item end def detail_display @current_selected = @item= Item.find(params[:id]) redirect_to :action => :...

RoR mySQL Error

Hi, I'm using Netbeans 6.5 and started a Rails project but getting the error below but I already have mySQL install. Running Windows XP. LoadError in TestController#index 126: The specified module could not be found. - c:/ruby/lib/ruby/gems/1.8/gems/mysql-2.7.3-x86-mswin32/ext/mysql.so RAILS_ROOT: C:/Temp/RailsApplication1 Applicati...

Rails: Elegant way to handle navigation?

Right now I have a navigation partial that looks like this (x10 buttons)... <% if current_controller == "territories" %> <li><%= link_to "Territories", {:controller => 'territories'}, :class => 'active' %></li> <% else %> <li><%= link_to "Territories", {:controller => 'territories'} %></li> <% end %> <% if current_controller =...

Errors on non model fields in rails

What's the best way to report errors on form fields not associated with a particular model in Rails? As an example, I have a form for the batch creation of user accounts with random users / passwords. It takes as inputs the quantity of users to make, information about what attributes all users should have, and information about the batch...

Locomotive slowing to a crawl

I have recently been building very small and simple apps using Locomotive 2.0.8. Until now it has been the ideal solution, but recently the application has slowed to absolute crawl. It takes literally 10 minutes to boot up, 5 minutes to add an existing or new project - and often these creations don't even work correctly. I can't imagine ...

Namespaced models in Rails: What's the state of the union?

Hi all, Since the beginning, Rails has had issues with namespaced models. As time went on, pretty much everybody gave up on using it. Myself included. With Rails 2.3 out, I'd like an update on the situation. Specifics questions I have in mind are: first off, is it good to go? table naming, what rule to follow? associations, how to d...

AJAX pattern in Rails for submitting small chunks of data

I have a web page with lots of small images on it. In a typical scenario user clicks on image and expects it to change with a new image. Requirements: When user clicks on image, it should be immediately known to a controller in an Ajax way. Some strings should be passed to a controller when user clicks on image. Controller does its...

Where do I put 'helper' methods?

In my Ruby on Rails app, I've got: class AdminController < ApplicationController def create if request.post? and params[:role_data] parse_role_data(params[:role_data]) end end end and also module AdminHelper def parse_role_data(roledata) ... end end Yet I get an error saying parse_role_data is not defined...

JavaScript file per view in Rails

As per 'unobtrusive JavaScript' recommendations I want to separate my JavaScript logic into separate files. However I don't know how to organize them. Should I: Just throw all application javascript into Application.js file and load it with layout page? This is simple approach but I will end up with a bloated Application.js. Some use...

Rails: ActiveResource - Can I set the ID explicitly?

I am using ActiveResource in Rails to manage entities in a separate database over REST. I have been trying to explicitly manage the IDs of the remote resources, as for the current case it is simplest to just re-use the local resource's ID, rather than maintain a different field. Unfortunately I have not been able to get this working as...

Using Warbler, how do I exclude Active Record from the bundled gems?

When using Warbler, what line(s) do I need to add to config/warble.rb to keep it from including Active Record in the bundled gems. I already have excluded Active Record in config/environment.rb as shown below. config.frameworks -= [ :active_record ] I tried the same thing only using config.gems in config/warble.rb, but to no avail. ...

DRY up js.erb files (include another js.erb file)

Hello, Most of my js.erb files contains something like this at the bottom: $("#flash_message").html("<%= escape_javascript(content_tag(:p, flash[:note], :class => "note")) %>"); $("#flash_message").fadeOut(2000); $("#loading").remove(); I would like to move these lines into a seperate file and then call that file from each of my js.e...

What are some good Ruby on Rails blogs?

Duplicate: http://stackoverflow.com/questions/402847/learning-ruby-recommended-blogs-to-read Hello everybody! I started learning Rails 6 months ago and so far I love the community behind it. There are plenty of forums and documentation resources available, but I haven't been able to find an instructional, consistently maintained instru...

What methods become available after I create an association?

I'm just getting rolling with RoR so I'm sure this is pretty basic. Let's say I have two models: Account and Transaction class Account < ActiveRecord::Base has_many :transactions end class Transaction < ActiveRecord::Base belongs_to :account end What methods (for each model) become available/are auto generated after I make t...

How do I define RESTful routes in Rails for a resource which has multiple key fields?

My User model has the usual id primary key, but it also has a unique login which can be used as an identifier. Therefore, I would like to define routes so that users can be accessed either by id or by login. Ideally, the routes would be something like this: /users/:id (GET) => show (:id) /users/:id (PUT) => update (:id) ... /users/lo...

Translating model with Globalize2 (rails)

I’m using latest globalize2 and rails 2.2. I wonder if the following is bug or feature: there seems to be a separate db query for each item in a dataset to get the translation. That doesn’t sound right since it may easily result in hundreds of queries. Illustration. Simple controller: def index @menu_sections = MenuSection.find(:al...

Can I do STI and still use polymorphic path helpers?

I am using Single Table Inheritance and have comments on all the subclasses. I am only using 1 controller for all the different STI types. When the form_for helper generates a URL for a subtype it tries to use a helper for the subtype, but I want it to use the helper for the parent. This is the error I get: undefined method `subclasst...

General question about Ruby

Hi All, I have installed the acts_as_versioned plugin from github.com in my rails application, and there was a block of code that I don't fully understand, I was hoping someone could clear this up for me class_eval <<-CLASS_METHODS def a_bunch_of_stuff .... end CLASS_METHODS I get that the methods inside the block (or whateve...