ruby-on-rails

Find tag with id including [] with Nokogiri

I have an html element like: <div id="spam[500]"> I want to search for this element by id, but it seems that nokogiri is getting confused by the []. I'm trying: doc.css("#spam[#{eggs.id}]") but to no avail. ...

Polymorphic Rails Associations (going backwards?)

Hi, I have a many to one polymorphic rails association in my rails app for a 'case' model. There are many things that have cases, so I access the case each thing has by doing 'thing_that_has_a_case.case'. However, I'm trying to go the other way and I'm not sure how. I have access to the case object but I want to access the thing tha...

Re-using a single file with basic ruby tested code in rails?

I got this code in a single file snippet.rb and it runs as expected. This script if from dzone snippet that fetches the thumbnail of the URL at the current time. Now I wan to integrate this functionality with Rails and here I'm stuck how to begin. Should I put this in some ruby file inside lib directory or make it modules??? I'm not muc...

Sequel in conjunction with ActiveRecord any gotchas?

I'm considering using Sequel for some of my hairier SQL that I find too hard to craft in Active Record. Are there any things I need to be aware of when using Sequel and ActiveRecord on the same project? (Besides the obvious ones like no AR validations in sequel etc...) ...

Environment-specific intializers for rails?

Can you configure rails to only run an initializer under certain environments? In my case I had to hack paperclip to work with Imagemagick on my dev box, so I have monkeypatched code I want only to apply to the development environ, not the production environment. That monkeypatch is saved as a file in config\initializers. The guides.rub...

Ruby on Rails field_for Form Helper Problems

Hi all, I'm using the field_for form helper with a loop: <% f.fields_for :permissions do |permission_form| %> <tr> <td><%= permission_form.object.security_module.name %><%= permission_form.hidden_field(:security_module_id) %></td> <td><%= permission_form.object.security_module.description %></td> <tr> <% end %> Th...

Weird uninitialized constant error (Rails)

The following code class Schedule < ActiveRecord::Base def self.get today = TZInfo::Timezone.get('America/New_York').utc_to_local(Time.now.utc).to_date end end produces the following error: uninitialized constant Schedule::TZInfo but only when I'm not running it from script/console. Thoughts? (Also, is there a ...

How Do I Correct mysql.rb Drivers?

For the last several days, I've been struggling to get ruby on rails to work on my mac. The main culprit is MySQL. Every time I fix one thing, another error shows up. I upgraded/downgraded MySQL to play nice with ruby, rail and gems, but nothing. My latest error is: !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please...

Manage Picture @ view

i have code like : <% if @photos.blank? %> No Pic <% else %> <center> <table> <tr> <% @photos.each do |c| %> <td> <%= image_tag(url_for({:action => 'image', :id => c.id}),:width =>'20%', :height =>'20%' ) %><br> <%= link_to "lihat" , {:action => 'show2', :id => c.id} -%> <% if logged_in? %> ...

Calculating the distance between two times

I'm trying to make a "better" distance_of_time_in_words for rails and so far I have this: http://github.com/radar/dotiw. However, at the moment it chokes on months + years, as shown by the specs. I'm at a complete loss! Help? Code added by Pax so no-one else has to search through github: module ActionView module Helpers module ...

rails acts_as_state_machine problem

I've installed the restful_authentication plugin. I'm Using rails 2.2.2. However, I can't seem to get past a certain error: "undefined method acts_as_state_machine" It doesn't matter if I call db:migrate or script/server, everything results in this same error. Any ideas? ...

including Modules in controller

I have done a module in lib directory in ruby on rails application its like module Select def self.included(base) base.extend ClassMethods end module ClassMethods def select_for(object_name, options={}) #does some operation self.send(:include, Selector::InstanceMethods) end end I called this in a...

What is the difference between Ruby and Ruby on Rails?

I have been studying ruby for the past few days and I have noticed there is Ruby on Rails. What is the difference between the two? Do they work to together? Is the syntax the same? ...

Add default value into prefix to my routes generated by the *_path methods

I have added into my routes file prefix value to each map.resources line. So it all looks like this: map.resources :subjects, :path_prefix => ':company' I have even added this line for default behavior map.connect ':company/:controller/:action/:id' which is not necessary (I believe) because all the routes are handled with resource...

Can I force a rails session to reload from a string?

I have a third-party app (an upload progress bar - swfupload) that I'm using with rails 2.3.3 that cannot pass along session information or cookies. I can, however, pack the session data from my app into the URI it will use to upload a file and retrieve that when I get the file. The trouble is, none of the magic hacks I see floating ar...

Ruby and Rails: Statement Modifiers in Views?

I have this code <% if approved %> <td>Flow Number</td> <% end %> and I'd like to shorten it using statement modifiers. Of course I can use <%="<td>Flow Number</td>" if approved -%> but is there a shorter way? I'd also like to get the markup out of quotes. ...

How to select only specific attributes from a model?

I want to select only specific attributes from a model(id,name). The SQL-command can be for example: SELECT id,name,username FROM Users Do you know how I can handle this? ...

How to Write JQuery in Helper on Rails

Please Help how to write JQuery coding in Helper function on Rails. ...

Rail cookies - Delete record from page after the date expiraton

Rails - using cookies how to delete record from page after the date expiraton. It should happen in view page <% cookies[:time] = {:value =>lead_row.created_at.strftime("%b %d, %Y") , :expires => 5.days.from_now } %> <% if cookies[:time]==nil %> ...should go to delete page..with out any link... <% end %> ...

RoR ActiveRecord dynamic finders: lying about interface?

Do Ruby on Rails' ActiveRecord dynamic finders have a problem in that they don't explicitly tell clients about their interface? Clients = client code or developers creating the client code. What uses the ActiveRecord. If you use the active record, is it clear from looking at the class what you can do with it, what it needs or how you ca...