ruby-on-rails

How do you set the value of a newly added ActiveRecord counter cache?

I have a model object which did not have a counter cache on it before and I added it via a migration. The thing is, I tried and failed to set the starting value of the counter cache based on the number of child objects I already had in the migration. Any attempt to update the cache value did not get written to the database. I even tried ...

Ruby on Rails - how to display a date in format i need? Converting from YYYY-MM-DD HH:MM:SS UTC to MM/DD/YYYY

I am a RoR newbie. I tried a lot of things, finally came to following: <td> <%= Date.strptime(request.baseline_start_date, "%Y-%M-%D %H:%M:%S %Z").strftime("%M/%D/%Y")%> </td> But this is also giving me an error: $_ value need to be String (nil given) But I know that request.baseline_start_date gives me value (tried printing it se...

Ruby on Rails on Windows XP CTRL+C in console not stopping mongrel

I am currently in the process of learning Ruby on Rails. I have been following the Learning Rails podcast and screencasts. I've run into a problem, well more of an annoyance. Every time the screencast has me kill the mongrel server I am forced to close the console window because CTRL+C isnt killing it as it should. I then have to open ...

How to remove .xml and .json from url when using active resource

...

How do I code a rake task to trigger a BackgrounDRb task?

I have a BackgrounDRb worker set up to run its 'sync' method every 15 minutes. Then, say, I want to run the method once just now. I was trying to wrap that in a rake task as follows: namespace :mytasks do task :sync do |t| worker = MiddleMan.worker(:my_worker) worker.async_sync end end But this doesn't work. It bails out w...

Pluses and minuses of using Factories in a Rails test suite?

I'm currently looking at a hefty Rails test suite. It's nothing I can get into specifics about, but the run time for the entire suite (unit/functional/some integration) can run upward of 5 minutes. We're completely reliant on fixtures and are we're not mocking and stubbing as much as we should be. Our next few sprints are going to be ...

God vs. Monit

Which one to use for process monitoring and why? ...

Access the value of an unsent form to use for remote_function

I'm curious how to solve this in a clean way. I've read a few forum posts but couldn't do something that works. I have a dropdown which — on change — should change a value for a remote_function. The remote_function only needs to be called when the propriate radio button is enabled. select: download <-- should affect rjs call to get a...

Reusing Ruby code across several Rails applications

I have developed a simple library in Ruby and need to use this in several Rails applications (some of which are not built yet). What is the best way to easily add this Ruby library to several Rails applications as and when required? Our team is running Ubuntu and our repository is Mercurial. Should I use a... Rails plugin? This would ...

Ruby on Rails time_select plugins?

Does anybody know any Ruby on Rails time_select plugins that have only one select box? So the select box has entries like "9:00 AM", "9:15 AM", etc.? I have seen a few plugins, but nothing like this. Thanks! ...

Ubuntu noob rails install fails on zlib

Hey all, hope you guys can help; I've followed about every tutorial on the net with no luck. I've just moved over to Ubuntu 8.10 as my dev box; it's my first serious foray into Linux as a daily-use OS, and I'm having a hard time getting Rails going. I have followed a number of tutorials which all seem to work fine, but when I try and u...

I need help figuring out the best way to query this in rails

I'm having a problem coming up with a query that would work for these models. I have three models that are connected. An Organization has many Users, and Users have many StatusEntries Basically this means I could do Organization.find(1).users.find(1).status_entries And have a list of status_entries returned to me. The problem is I ...

Nested params issue with Rack 1.0 / Unable to freeze Rails 2.3.2.1 - Please help

Hi, I have a very strange issue. I upgraded my Application to Rails 2.3.2 without any problems, then freezed it to vendor/rails and worked through all my specs after I also upgraded Rspec to 1.2.4. At some point (I cannot exactly tell you when) nested parameters didn't work anymore. That means the server receives something like: { "po...

How do I copy files between buckets using s3 from a rails application?

I am currently developing a rails application that tries to copy/move videos from one bucket to another in s3. However i keep getting a proxy error 502 on my rails application. In the mongrel log it says "failed to allocate memory." Once this error occurs the application dies and we must restart is. ...

Running multiple web frameworks on one machine?

I want to start experimenting with all these different web frameworks that are available. I was wondering if they could all run in one machine at the same time? I know that all my database services can all run at the same time, along with the Javascript frameworks, but what about something like Rails and Java applications? Can those pl...

Why would association.build not assign parent_id to it child?

I've got the following models: In plan.rb has_many :tickets and in ticket.rb belongs_to :plan validates_presence_of :plan_id When executing the following code in the controller @plan.tickets.build( ... ) @plan.save save fails with error_message for ticket: plan can't be blank. (plan is valid.) ...

What is the difference between [X,Y,Z].each {|m| include m} and include X, Y, Z ?

Note This originally started as a question about 404 errors, but now it's a question why the patch that I applied would make a difference. How do you get a cached action to return a 404 on all requests that raise an ActiveRecord::RecordNotFound exception, not just the first request? For example, if you start an empty rails project, add...

how do I add gravatar/identicons into ruby on rails?

I have looked at the following, but they aren't clear, particularly the reference to DataMapper and gem dependencies. all I want as an outcome is to be able to take my @user.email value that is in a |do| loop and display a gravatar where identicon is set to "y" -- in other words, those cute seemingly random drawings! But when I look at...

how do I retrieve attributes of different models from controller?

I have a Vendor controller for show: def show @vendor = Vendor.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @vendor } end end In my View for Reviews (where Vendor :has_many Reviews) <% if @vendor.reviews.empty? %> No Analyst Reports yet <% else %> <% for review in @vendo...

how do I use link_to link to different controller and model?

Hi, I currently have the following for-loop. This is in the 'view/vendor/show.html'. I set up a 'vendor :has_many :reviews' and this is the for-loop: <% for review in @vendor.reviews %> <%= review.user_id %> <%= review.summary %><br /> <%= link_to 'More', @review%> <hr class="left span-5" /> <% end %> For the link_to I would...