ruby-on-rails

Best way to implement Categories and Subcategories with flexible depth in Rails?

Hi. I have a Category and Subcategory models in my project. I would like to have many sub-levels in a flexible way. I thought making a self referential "parent" foreign key but I'm not quite sure how to do it. Any ideas? Thanks! Cat1 Sub1 SubSub1 SubSub2 Sub2 Cat2 Sub1 Cat3 Sub1 Sub2 SubSub1 ...

How to modify restful_authentication plugin setup in Rails ?

Hi. I installed restful_authentication a while ago in my project, everything works fine, except that now we requiere the users to activate their accounts via email. I forgot to include the option "--include-activation" when I ran the generate script, is there a clean way to add it now? Or should I re-install the plugin? If so, how can i...

Setting default radio button on edit

So I'm trying to setup scaffolding to use radio buttons for the format button. It definitely works to add a new and edit. The problem is when I go to edit an entry the correct radio button isn't selected by default. <% form_for(@cinema) do |f| %> <%= f.error_messages %> <p> <%= f.label :title %><br /> <%= f.text_field :title %> <...

Time calculation on ruby on rails and ajax

Hello, i have a form with 2 time_select fields, a customer calls and we need to select time of the support call begin and end. I would like to know how to send the values to a function using ajax, would it be a good idea to use a observe field for each one of them?. here is my form: <p> <%= f.label :inicio %><br/> <%= f.time_...

Rails routes direct index action to show action

So I created some rspec_scaffold for an Exercise model and added "map.resource :exercises" to my routes file and I was surprised when the "/exercises" url rendered the show action. What the heck? Why doesn't that render the index action? rake routes new_exercises GET /exercises/new(.:format) {:controller=>...

Multipart Form Problem in Ruby on Rails

I am developing a Ruby on Rails app that utilizes a Java Uploader. The uploader creates a multipart HTML form and submits it to my upload controller. For testing purposes, I have also created a simple multipart HTML form with a single input generated with file_field_tag. The HTML version behaves as expected, and generates the following...

rails routes for permalink with namespaced class

this one in my routes works perfectly: map.connect ':permalink', :controller => 'pages', :action => 'show' for this class: class PagesController < BackendController and on /xxx/pages it is shown like this: <%= link_to "#{item.link_name}", {:controller => :pages, :action => :show, :permalink => item.permalink} %> which will generate ...

Simplifying wide, unnormalized tables in Rails

Background I'm designing a Rails app to record research data. Most of it can be conceptualized as being "survey" (or "questionnaire") data. We already have several Access databases and CSV files that hold this data. The existing design is that each survey has its own table with one column per question. Many of these tables have 100+...

Ruby on Rails: using nested named_scopes

I just got referred to stackoverflow by a friend here to help with a problem I am having. I am fairly new to ruby on rails and I am working on a collaborative project where we have a script (medal_worker.rb) that is scheduled to run at a fixed intervals to award people various medals based on various participation and success on our web...

How to add and remove nested model fields dynamically using Haml and Formtastic

We've all seen the brilliant complex forms railscast where Ryan Bates explains how to dynamically add or remove nested objects within the parent object form using Javascript. Has anyone got any ideas about how these methods need to be modified so as to work with Haml Formtastic? To add some context here's a simplified version of the p...

render_to_string in lib class not working

I'm trying to use delayed_job to update a remote database via xml In my lib folder I put a file with a class that should do a render_to_text with template.xml.builder, but I get: undefined method `render_to_string' for #... What am I doing wrong? ...

Survey table/model design in Rails

I have some survey data which is currently stored in tables that are 100+ columns wide (one column per question). To simplify it, I've been thinking about making some models like: Survey Question Response However, I'm not sure how to approach it through Rails because: I need nice views (better than autogenerating forms) for many s...

smarter character replacement using ruby gsub and regexp

Hi guys! I'm trying to create permalink like behavior for some article titles and i don't want to add a new db field for permalink. So i decided to write a helper that will convert my article title from: "O "focoasă" a pornit cruciada, împotriva bărbaţilor zgârciţi" to "o-focoasa-a-pornit-cruciada-impotriva-barbatilor-zgarciti". Wh...

Where is the best place to hold system-wide helpers\libs in Rails app?

Hello. I'm refactoring on old Rails app, and I have a lot of little methods\helpers that keep piling up that are not controller\model specific but are rather system-wide specific. For instance I have a method that determines whether the system is Windows or not: def windows? (/win|mingw/).match(RUBY_PLATFORM) ? true : false e...

Is there any way to get the date modified from Net::SSH or NET::SFTP commands in ruby?

Hi there, Is there an easy way to get the date modified of a file by using Net::SFTP? It'd be nice to be able to do this: Net::SFTP.start('some_server') do |sftp| sftp.dir.glob('*').each do |file| puts file.mtime end end But that's not possible (to my knowledge). Berns. ...

Ruby on Rails issue..mainly dealing with ruby gems/bundler

I was trying to use rspec and for some reason it wasn't working. I think it lacked some dependencies or something. Everything else in Ruby 1.9 was working perfectly on my laptop though. So I did a ruby gems system update (sudo gem update --system). I then did a gem update (sudo gem update). When I tried to run or create apps in rails I g...

Where can I download ruby on rails?

Might sound like a stupid question I guess but rubyonrails.org is just an advert right now, which isn't a good sign. ...

Why Ruby on Rails uses default Prototype?

I just recently started learning RoR. In Rails by default available Prototype. Why uses it is this library? Why is not jQuery, Dojo, Mootools, ExtJS ... ...

2 Spaces or 1 Tab, what's the standard for indentation in the Rails Community?

I've noticed that most of the HTML/XML/HAML that gets generated from plugins uses 2 spaces instead of 1 tab. I use textmate and have tabs set to 4 spaces for HAML/HTML/XML and 2 spaces for Javascript/Ruby, but I only have to press the tab key once to get nice indentation. Pressing the space bar twice and delete twice seems like too muc...

What does this random number do: /javascripts/rails.js?1271798101

I think I remember reading that that has to do with telling the browser not to cache it or something. How does this impact browser caching and application performance in production? When does that number change? <script src="/javascripts/rails.js?1271798101" type="text/javascript"></script> ...