ruby-on-rails

How to excute commands with in Rake tasks

I have the rake tasks in my rails application. i want to run a commandline commands with in rake task. how can i do this. i tried by the following but fails desc "Sending the newsletter to all the users" task :sending_mail do run "cd #{RAILS_ROOT} && ar_sendmail -o -t NewsLetters -v" system "cd #{RAILS_ROOT} && ar_sendmail -o -t New...

ujs link problem in rails3

hi I want to add a remote link via javascript(mootools). This code adds the link, but the click on this new link('delete foo 1') sends an html request and not an ajax request. Why doesn't it send an ajax request? Can anyone help me. Thanks <div id="add_link"> add link </div> <%= javascript_tag do %> $('add_link').addEvents({ 'cl...

Using authlogic, asking for email, should facebook's login window redirect a new application to it's own window?

When I ask for email permissions, my facebook popup window redirects to my site in its own window, whereas if I do not ask for email permissions the facebook window closes and my site redirects as normal... so asking for email seems to make something go wrong. I see this in myserver logs: makes this appear in my server logs: Completed ...

Testing against the 'current_user' with Devise in Rails 3

I'm just starting out with Ruby and Rails, trying out Devise with Rails 3. I've got a loop around a list of Posts, each of which has an associated user. I only want to display editing controls for those posts which are associated with the current user. <% @posts.each do |post| %> <%= link_to "show" %> <% if current_user = post.user ...

Request-scope variable that I can use across all instances of a Rails model class

I'm writing a Rails app and I have a variable whose value takes a significant time to calculate. The variable must be re-calculated at the beginning of each request. If possible, I'd like to access this variable from different model classes but I'll settle for one calculation per model. EDIT: e.g. something like this: module MyHelp...

Passenger with Nginx cannot find rails 2.3.8 gem

I have been trying to setup nginx with passenger for a few days now and keep running into problems. When I go to my Rails application with my browser it says: Missing the Rails 2.3.8 gem. Please gem install -v=2.3.8 rails, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comme...

Ruby on Rails cannot find initializer?

I cross posted this to Serverfault, but I'm not sure if this is more development or server related, unfortunately. =( Hello, I am trying to deploy an app to a fresh Ubuntu 10 installation using Passenger 2.2.15, Rails 2.3.5, Ruby 1.8.7, and Apache 2.2.14. However, even with a default rails app (sudo rails defaultapp), I am receiving t...

LoadError when using heroku db:push

When i use "heroku db:push" to transfer my local data to heroku,i got this error message: Sequel::AdapterNotFound -> LoadError: no such file to load -- sequel/adapters/mysql2 I already install the mysql2 gem, and i am using rvm with ruby 1.9.2 in Mac OS X Snow Leopard. ...

delayed_job and rails 3 not loading jobs

I am trying to start the delayed_job daemon but it's returning the following error. $ rake jobs:work * Starting job worker host:Kelvin-Pompeys-MacBook-Pro.local pid:4712 rake aborted! Job failed to load: invalid subclass. Try to manually require the required file. After a bit of Googling I found the link below which suggests that I r...

transpose a html table

Is it possible to transpose an html table (without javascript). I m generating a table with rails (and erb) from a list of object. So it's really easy and natural to do it when each row correspond to one object. However , I need each object to be represented as a column. I would like to have only one loop and describe each column rather ...

resources :users, :as => 'members' equvalent in Rails 3

So in Rails2 you could setup a route like this: resources :users, :as => 'members' This way you still have your users_path but it matches /members Now, how do you go about doing this in Rails3? :as parameter here means totally different thing and I can't find what makes it work as before. ...

Replacement for column_names when using Mongoid with rails 3 and dry_crud

I've been doing a spike on Rails 3 and Mongoid and with the pleasant memories of the auto scaffolding in Grails I started to look for a DRY view for ruby when I found: http://github.com/codez/dry_crud I created a simple class class Capture include Mongoid::Document field :species, :type => String field :captured_by, :type => Str...

In Rails, why the non-parallelism for "render :json => @data" and "render :xml => @data.to_xml" ?

In Rails, we can respond_to do |format| format.html format.json { render :json => @data } end so it knows to automatically show the @data in json format, but when it is xml, it needs to be format.xml { render :xml => @data.to_xml } why does it need to explicitly convert @data into XML? Can't it be just like json's case? to...

Setting up virtual hosts for Rails apps on Apache and Mongrel

I have a single Linux server running 3 site on Apache. Let's call them RailsApp1, RailsApp2, and SimpleApp. Both Rails applications are using Mongrel clusters. The other application is just a single HTML file. I have different Virtual Host files setup in Apache for each site, as well as mongrel_cluster.yml files for both Rails sites (cod...

Handling standard user facing scenarios

*I was wondering if i could do all these in javascript, as opposed to having rails helpers In my application, there are several types of "if-else" UI cases. This is a fairly common scenario, and i wonder if anyone has a tidy way to do these? EG 1) There might be several types of links with the same behavior: "upvote", etc. If i...

Rake db:migrate error "don't know how to build task"

I've got a table where I used integer on a field which needs decimal places, so I'm trying to create a migration which changes the field type from integer to float/real. My database is sqllite3 and I'm using rails3. I ran rails generate migration ChangeMeasureColumnOnIngredients to create the initial migration files, then updated th...

How do I detect the client has javascript turned on/off from Rails?

I don't want to deal with users who have javascript turned off, so I want to just prevent them from using my application. I want to detect if the user has javascript turned on so I can redirect them to a page that tells them they need to use javascript. I'm sure its in the request header. Anyone have any ideas how I can do this? ...

Better way to access individual Rails ActiveRecord error?

I'm trying to access the type attribute of an ActiveRecord::Error object. The reason I'm doing this is because I want to redirect a user to a different page depending on the type of validation that failed (an attribute can fail validation in several ways, so the attribute itself is insufficient). The only way I've found that I can do th...

Rails: run rake tasks like migrations

My dev team needs to more precisely run rake tasks. There are certain tasks that need to be only run once after a specific code change. Without getting too specific, it would be like needing to update certain existing users records after a new business rule for new users is implemented in the code. We like how migrations use a db table...

Categorizations for Ruby on Rails (or tags)

Hello, I have Articles, Profiles, and Comments. What would be the best way to categorize new instances of each of these? When a user creates a new article, profile, or comment, he must select a category for them. I want to have a drop down menu from which he can select the categories. The categories are different for each Model, and what...