ruby-on-rails

rails: Scheduled jobs but run at most one at single time

Hi, I have the scheduled job which run every 5 seconds. I'm now using backgroudRB for scheduling. But sometimes, the job may take more than 5 seconds and i don't want more than one job is running at the same time. In .Net, we can use Mutex class, but I'm not sure about what should I use in rails application. Thanks. ...

Ruby on Rails 'find' question

I'm currently using: @user = User.find(params[:id]) @posts = Post.find(:all, :conditions => ["user_id = ?", @user.id]) @comments = Comment.find(:all, :conditions => ["user_id = ?", @user.id]) Which identifies the user, and lists all their comments they've made. However, I want to set a local variable for use in the _comment.html.erb ...

haml formbuilder

I'm converting an old program over to haml and I've got a problem with my custom formbuilder. The problem is simply adding a line feed between a fields label and input tag. Here is the original FormBuilder: # Custom FormBuilder class SuperFormBuilder < ActionView::Helpers::FormBuilder # Create an array of helpers to override with o...

Ruby on Rails question

I'm currently using: @user = User.find(params[:id]) @posts = @user.posts @comments = @user.comments To display all my comments with this code in my template: <% @user.comments.each do |p| %> <p>Commented on <%= p.post.user_id %>'s post</p> <p><%= p.body %></p> <% end %> Each post has a 'user_id' column which is the user's ID fo...

What is wrong with this attempt to create a route to delete a record in RoR?

I have a model called NoteCategory, which is functioning as a join table between Notes and Categories. Up till this point, I have used scaffolding to do everything in RoR. I'm trying to learn how to do some stuff more manually. I want to have a link that will appear next to each category on a note, that will remove the category from t...

Do I need to close my connections to Amazon S3 in my Rails App?

I'm migrating my rails app to Heroku and need to change my file upload functionality to use Amazon S3 instead of local storage. I am using the aws-s3 gem and have this working but just want to make sure that I'm doing things right and not creating problems for myself. In my uploading code I have the following; AWS::S3::Base.establish_c...

logout should redirect to :back unless :back requires a user

When logout is clicked I want to redirect back to the page the user was on unless that page requires a user to be logged in. scenario 1 - "back" requires a user 1) User clicks logout from user account page 2) redirected (ultimately) to root_path scenario 2 - "back" does not require a user 1) User clicks logout from (not user required) ...

browser displays the javascript code instead of html page in rails

Hi, I got a weird problem, here is the snippet of my code, View 1: <%= javascript_include_tag :defaults %> <% remote_form_for (@group, :group, :url => { :action => 'addgroup' }, :update => 'activitypage') do |form| %> <%= submit_tag "Add!", :class => "submit" %> <% end %> Method 'addgroup', def addgroup ##<some code her...

How to keep track of selections in sequential form

I have what is essentially a form, only the fields depend on the previous selections, and the type of form object aren't always typical form objects. For example, the first choices are simply in the form of links. It could be a list of teachers, where when you select a teachers name, the classes that teacher teaches is then displayed in...

Which version of searchlogic works with Rails 2.1.0 ?

Hi, I just installed searchlogic 2.4.24 for my Rails 2.1.0 app but got the following error :- ..aliasing.rb:31:in alias_method':NameError: undefined methodmerge_joins' for class `Class' Is it a version conflict? Does anyone know which version of searchlogic works with Rails 2.1.0? Thanks! ...

How do I dynamically create a named_route in rails?

I currently have this in my ApplicationController def account_path eval "#{current_user.type.downcase}_account_path" end I use it for redirects, etc. But I also want to use it in the view (for link_to's etc). Is this is a legit case to share code between the controller and view to keep it DRY even though it breaks MVC? ...

Problem with getting a name string from a query

Hello all, I'm pretty new to rails and mongoid and I have a problem with extracting a string out of a query. I have a class Filteroption class Fieldoption include Mongoid::Document field :name, :type => String field :option_id, :type => Integer end and with this entries +--------------------------+-------------...

Properly loading ruby modules in Rails.

I'm not sure what I'm doing wrong here, I have a file in lib/acts_as_votable.rb, it's just a votable system for the app. module ActsAsVotable end module ActiveRecord class Base class << self cattr_accessor :votable def acts_as_votable has_many :votes, :as => :voteable end def votable? m...

Rails - email subject is gibberish in hotmail

Hi, Sending emails works perfectly for all major email clients, except for hotmail (and some other), it shows as: =?windows-1255?Q?Z33=30_=F9=22=E7=20=F2=E1=E5=F8_=F9=E5=E1=F8=20=E1=F9=E5=E5=E9=20=36=30_=F9=22=E7=20=EC=22=EE=F8=E2=E5=E6=E4=22=2C_=E1=E9=FA_=F7=F4=E4=20=E5=EE=E0=F4=E9=E9=E4_=EE=F9=F4=E7=FA=E9=FA=2C=20=E1=EE=FA=E7=ED=20=F...

Can't get French accents to show for some error messages in Ruby on Rails

I have a site which is in two languages: English and French. There is a form. For some reason some of the error messages on the form display the French accents while other error messages will not. The pages are encoded in charset=utf-8. Any ideas why this is happening and how I can fix this. I have even encoded the translations using...

Cucumber prevent from clearing database

Hello, due to a heavy growing project I'm running into the trouble that the database rebuild process of cucumber really takes a long time. Since it is a application where the actual content of the table doesn't matter, I'd like to skip the rebuild process. Unfortunately wether cucumber nor database_cleaner seem to support this, doesn'...

Testing view helpers

I'm currently working on a Rails plugin used for generating iPhone specific HTML meta-tags. I'm trying to use ActionView::TestCase for unit tests but keep getting the same error. See file contents and error below. Any ideas or help would be much appreciated. test_helper.rb require 'rubygems' require 'test/unit' require 'active_support'...

Dynamic Role Authorization in Rails using a database. Declarative Authorization the best choice?

I will need to provide dynamic role assignments (Roles/ Privileges) .More clearly, an end user should be able to create a role, assign permissions to a new user. So I was thinking of storing roles and privileges in a table for each user. Is there a smart way to do this (any other plugin?),or or should I write code to do this with Decl...

Passing of text_field with array value

this code is used to generate 6 empty boxes on thesame row <% while counter < 6 do%> <%name ="txtwinentry1"+counter.to_s %> <%=password_field "txtwinentry1" ,nil,:size => 2,:class => 'xstyle',:id => name %> <%counter = counter + 1%> ...

Override devise registrations controller

I have added a field to the sign-up form that is based on a different model, see http://stackoverflow.com/questions/3544265/how-do-i-use-nested-attributes-with-the-devise-model for the gory details. This part is working fine. The problem now is when I save, it is failing in the create action of the registrations controller that is suppl...