ruby-on-rails

Rails 3 - Determine if a HASH contains a record

Hello, For a user I have the following as an example: [#<Permission id: 1, project_id: 3, role_id: 1, user_id: 1>, #<Permission id: 43, project_id: 2, role_id: 1, user_id: 1>, #<Permission id: 44, project_id: 4, role_id: 1, user_id: 1>, #<Permission id: 45, project_id: 5, role_id: 2, user_id: 1>, #<Permission id: 46, project_id: 6, rol...

Trying to deploy app via Capistrano for first time, having problems

I am trying to deploy a Rails app via Capistrano but am having problems. The messages that get returned in Terminal are as follows: victor$ cap deploy * executing `deploy' * executing `deploy:update' ** transaction: start * executing `deploy:update_code' executing locally: "git ls-remote [email protected]:victory/PUM.git HEA...

relative_url_root in ActionMailer

What's the equivalent of relative_url_root in ActionMailer? I've tried setting it up in default_url_options, but it appends the parameter in the query string. Adding :skip_relative_url_root = false doesn't work either. Using :host = 'somehost.com/subdir' does work, but is that appropriate? Thanks! ...

Options_for_select - how to select what's in the database?

I have a complex form (like Ryan B's Complex Form Railscasts) where I have a few levels of database tables being altered at the same time. The code for this dropdown box works in that it delivers the correct integer to the database. But, despite numerous attempts I cannot get it to correctly reflect the database's CURRENT value. How can...

flash reappears on refresh

I show flash messages in my rails app using javascript (essentially every flash message is an overlay div). The following partial is included in my main layout file and it takes care of displaying the flash. I notice that if I refresh a page, the same flash message keeps reappearing. Anyway to get rid of this? I know I can call a flash....

Rails 2.2.2 - Missing template error when trying to render a partial in a subdirectory

I'm getting the following error when Rails tries to render my layout located in app/views/layouts/application.html.erb: Missing template shared/_header.erb in view path /home/me/checkout/site/app/views: Extracted source (around line #11): 8: <body> 9: <div id="wrap"> 10: <div class="clear">...</div> 11: <%= render :partia...

Toggling multiple divs when those divs are new (no IDs)

I am combining div toggling with complex forms: http://railscasts.com/episodes/75-complex-forms-part-3 My specific situation: I have a few nested fields being built in table/new.html.erb and Customer/_customer_note_fields. Ordinarily, I would do something like the following to have toggled divs: # view <a class="toggle" rel="toggle[exp...

Rails 3 - Help with a FORM_FOR tag

Hello, I have the following form_for tag: <%=form_for [:project, @permission], :remote => true do |f| %> <form method="post" id="edit_permission_52" data-remote="true" class="edit_permission" action="/projects/52/permissions/useronspace" accept-charset="UTF-8"> The ID looks right = edit_permissions_52 But the action path is all me...

In Rails, if not using Bundler, what is the most preferred way of freezing a gem into the project?

Our project is Rails 2.2.2, maybe it can't use Bundler? (or maybe for some other reasons, Bundler cannot be used) Then in that case, what is the most preferred way of freezing the gems into the project source tree? Some that I know of are: rake gems:freeze needs gemsonrails and it doesn't work with the current gem 1.3.7 rake gems:...

RESTful request to Rails app using curl ignores AuthenticityToken

Is there any reason that AuthenticityToken would be ignored when executing a REST HTTP request using curl? curl http://localhost:3000/Asset/9f3cb180-e410-11de-8a39-0800200c9a66.xml -X DELETE The above will execute remove an Asset of the given ID from the database with no regards to what the AuthenticityToken is (usually nil). class ...

How should I test a model with a lot of attributes and validations in Ruby on Rails?

Hi I have a user model with a lot of attributes and validation that I require to go in. I want to develop my application using test-driven development but am having a hard time writing simple tests for validations such as no blank emails, unique emails, proper email address. So what's the best way to start writing tests? ...

simple jquery plugin to upload a file via jQuery (Ruby on Rails)

Hello, I'm looking for a simple jquery plugin to upload a file without FLASH. For Ruby on Rails. Single file upload progress bar indicator and all the bits have been uploaded. ...

Rails 3: Lazy loading versus eager loading

In Rails 3, are these the same, or different? How do they differ? o = Appointment.find(297) o.service o = Appointment.includes(:service).find(297) o.service ...

rails3 default_scope, and default column value in migration

class CreateCrews < ActiveRecord::Migration def self.up create_table :crews do |t| t.string :title t.text :description t.boolean :adult t.boolean :private t.integer :gender_id t.boolean :approved, :default => false t.timestamps end end def self.down drop_table :crews end end ...

Ruby IMAP library doesn't decode mail subject

I have got mail message with following subject in my Gmail accout: "400, значение, значение" Here is the code I use to grab mail: imap = Net::IMAP.new('imap.gmail.com', 993, true, nil, false) imap.login(LOGIN, PASSWORD) imap.select("INBOX") messages = imap.search(['ALL']).map do |message_id| msg =imap.fetch(message_id, "ENVELOPE")[...

sort by in Array ruby

I have array a = ["aaa", "bee", "cee", "dee"] I want have new array with sort as like: a = ["cee", "aaa", "dee", "bee"] Please help me. thanks. ...

Regex "\w" doesn't process utf-8 characters in Ruby 1.9.2

Regex \w doesn't match utf-8 characters in Ruby 1.9.2. Anybody faced same problem? Example: /[\w\s]+/u In my rails application.rb I've added config.encoding = "utf-8" ...

Accessing objects in semantic_fieds_for loop / formtastic

Model has accepts_nested_attributes_for for the relation and the form is as follows: = semantic_form_for @obj, :url => path do |f| = f.inputs do = f.input :name = f.semantic_fields_for :photos do |p| = p.inputs :desc = f.buttons The form works well and everything is fine. However, I would like to display each phot...

Order a collection as DESC

<%= render :partial => 'event', :collection => @events.sort_by(&:event_at)%> This code shows a collection ordered as ASC, but i want to order this collection as DESC. How can I achieve this? ...

Ruby Mongo or Mongoid concurrency problem

I am having what I think must be a concurrency problem. I am using passenger, rails 2.3.5, mongoid 1.9.2, and mongo ruby driver 1.0.9. I am using jQuery to request data that is pulled from MongoDB and then rendered in the browser. Everything is working great until I started to make two such requests at the same time. In the model the...