ruby-on-rails

Ruby on Rails: One to many relationship view

New to rails and trying to get a one to many relationship up and running. I have it working in the Model and Controller, but I'm having trouble getting it up and running in the views. class Project < ActiveRecord::Base has_many :non_labor_expenses end class NonLaborExpense < ActiveRecord::Base belongs_to :project end I manually c...

global access to a collection in rails

where should i define a variable(collection) for it to be globally accessible both in all controller views and in layout? somewhere in Application controller or in session? as an example if current_user.has_role("admin") @groups=Group.all else @groups=Group.all(:conditions => {:hidden => false}) end @groups collection has to be acc...

show products in category in a new page

I have a problem in Rails, I want to show products in each category on a separate page when user clicks on the proper link, categories and products have HABTM relation, I can see the results but I don't want to show them in default pages(routes). Should I create a new routes rule or this can be achieved in controller and view without edi...

scoped_by greater than or less than in ActiveRecord (Rails)

I want to use a dynamic scope in Rails where I filter by date. I want to do something like this: Foo.scoped_by_created_on(>the_future).scoped_by_created_on(<the_past).find(:all) Is this possible or am I stuck writing a :conditions hash? ...

Rails ActiveResource

Hi There, We are in the process of building a REST compliant API. The backend is implemented in PHP and we want the interface to follow the convention over configuration motto. Many of the API consumers will be Rails developers, and following a TDD strategy to building out the API, we've considered using ActiveResource to implement a ...

delete multiple item by checkbox

I want have this ability to select multiple items with checkboxes and delete them in one place this is the code : <% @products.each do |p| %> <%= check_box_tag "product[]" , p.id %> <div class="product_image"> <%= image_tag p.photo.url(:thumb) , :alt => "#{p.name}" %> </div> <%= link_to "<h3>#{p.name}</h3>" , edit_product_path(p) %>...

STI Inheiritance in Rails. Issues with find.

I am having an issue with searching for records in my STI table due to my inheritance structure class User < ActiveRecord::Base class LegacyUser < User class AuthUser < User class SuperUser < AuthUser class FieldUser < AuthUser class ClientAdmin < AuthUser The problem is that find does not work for the AuthUser Model. The...

Rails: the better app infrastructure

I'm trying to make a comment system, identical to the stackoverslow's one. There's a 1-st level comment, and a bunch of a second level comments, attached to it. The first straightforward idea that came up in order to do that, was to create a separate model, sub_comment. But I still got this feeling, that I should inherit the initial comm...

local methods act differently when called with/without self. Why?

I have model called User with a has_many relationship to UserFilter. UserFilter has a belongs_to relationship to User. Within the User model I have a method called update_user_filters(filter_params_array) This method modifies user_filters like something like this def update_user_filters(filter_params_array) new_filters = [] old_fi...

Rails, Extjs and SQL Server

So I'm running Extjs on top of Rails 2.3.3 against a SQL Server DB. I'm able to pull data from the DB and display it, but I'm unable to create, update or destroy. Oddly enough, it's not throwing console or any other errors on attempted updates or deletes -- it simply fails. On create, an InvalidStatement error gets thrown, probably r...

How to iterate over an array of arrays

What's the best way to iterate over an array of arrays? sounds = [ [Name_1, link_1], [Name_2, link_2], [Name_3, link_3], [Name_4, link_4] ] I want to the output in html ul/li structure Name_1, link_1 Name_2, link_2 Name_3, link_3 Name_4, link_4 ...

How can I get rails to send javascript errors to the log, not alert?

I'm new to Rails. Javascript errors to an alert box injure my soul. Is there a way to send it to console.log() instead of alert()? ...

Check if record was just destroyed in rails

So there is record.new_record? To check if something is new I need to check if something is on it's way out. record = some_magic record.destroy record.is_destroyed? # => true Something like that. I know destroying freezes the object, so frozen? sort of works, but is there something explicitly for this task? ...

How can I make an array of a block in rails?

I want to use to_sentence method on the block of code to return the names with , separated : <% @products_in_category.each do |pic| %> <%= pic.name %> <% end %> How can I do this ? ...

ruby-on-rails routing-filter google sitemaps

Hi, I'm generating sitemap.xml for google. I have also the Sven Fuchs' routing-filter excellent plugin. But all links look like this one - http://localhost:3000/en/posts/54 Is there any way to switch the locale in the same "view"? Thanks. ...

How to reroute all content that ends in `.html` to the root route (by only changing routes.rb)?

I have a bunch of expired content at URLs all ending in .html from a legacy static HTML site: example.com/a.html example.com/b.html Rather than display a Rails error page that says: Routing Error No route matches "/a.html" with {:method=>:get} I want to reroute all content that ends in .html to the homepage (the root route): map.r...

Rails: How to associate users belonging to companies belonging to a user?

I have a User and Company model. There are three possible roles that a user can have: Owner, Agent or End-User. Agents and End-Users belong to companies, which in turn belong to Owners. How would you go about making the association between these models? Would a habtm association be useful here? I.e Users can have and belong to many ...

Pentaho Acegi Security Framework Digest Authentication & Ruby on Rails

Hi all, At the moment I have a Ruby on Rails application which maintains my Users, I have a seperate application (Pentaho) which uses Acegi/Spring Security to authenticate Users. I have been able to change the way Acegi/Spring Security authenticates Users and now it points to my Ruby on Rails application's database and I can get Users ...

Transitioning from Scrubyt to Nokogiri- Write to XML or Hash?

I'm trying to transition this bit of code from scrubyt to nokogiri, and am stuck trying to write my results to either a hash or xml. In scrubyt it looks like the following: require 'rubygems' require 'scrubyt' result_data = Scrubyt::Extractor.define do fetch "http://rads.stackoverflow.com/amzn/click/0061673730" results "//d...

In Rails, how do I use RESTful actions for a resource that is the join in a many to many relationship?

I have the following models: class User < ActiveRecord::Base has_many :subscriptions end class Subscription < ActiveRecord::Base belongs_to :user belongs_to :queue end class Queue < ActiveRecord::Base has_many :subscriptions end I want to have some meta-data in the Subscription class and allow users to maintain the details o...