ruby-on-rails

Rails TZInfo::Timezone help

I use Rails TZInfo::Timezone How could i add new city in this. For example : I want to show 'Washington, DC' time zone my application,but there is no mapping available for that city. I retrieve all timezones using TZInfo::Timezone.get() method Please give some expert suggestion. ...

Rails app and rake db:migrate can use different database credentials?

Hi! Does anyone know if Rails can be configured so that rake (e.g. db:migrate) uses a different database user to the app itself? It seems to me that the database user for the app does not need permissions to drop tables and columns, where as db:migrate does, so separate should make for a more secure app...? But I assume by default bot...

Adding post commits to Rails application?

Hi Everyone, I am using the following gem in my rails application: http://github.com/fnando/post_commit I am trying to learn how to send data to service providers such as Campfire on creation of a record in my application. Using Campfire as a test I have the following in my kase.rb model: # Campfire post_commit :campfire do author...

Strange problems with Jammit

Hi, i use Jammit to pack all the .css and .js files in my project I faced a strange problem, that really confused me... When Jammit deals with .css, it kills some css rules. The rules: background-image: -webkit-gradient( linear, left bottom, left top, color-stop(0, #111111), color-stop(1, #303030) ); background-image: -moz-linear-g...

Rspec model spec

How do i cover the below method using Rspec? def validate if !self.response.blank? && !self.response.match("<").nil? self.errors.add :base, 'Please ensure that Response field do not contain HTML(< and >) tags' end end Can anybody help? ...

how to generate link for unsubscribing from email

I have a simple rails app where user can send a mass email to 10+ people. In this email I'd like to always have a link at the bottom which the end user can click to unsubscribe himself from the notifications. I don't have much idea how I should tackle this. can there be just a generic link in the email which users click then enter th...

wildcard subdomains in development with passenger

It really bites having to add an alias every time you need a subdomain on your development machine. Is there a way to configure passenger to use wildcards so that i can access randomsubdomain.mysite.local ? ...

Ruby object in my JavaScript file

I have a Ruby object and I want to use that object in JavaScript. I haven't seen that type of thing, but I want a Ruby object in my .js file. Is this possible? Thanks in advance ...

Nested form: fill collection via array

Hi, I have a self join model like: news relatednews No I have a form_for and want to fill relatednews but not via multiple elements in the form via fields_for (e.g. input fields) but with one input field that hold all id´s of relatednews. like (1,2,3). I want to store this and read it back without to break the relational activerec...

Ruby on Rails with Unobtrusive JavaScript - Managing URLs

I'm using a modular system of JavaScript files when working in Rails - basically each view will have its own module in a .js file. My issue comes when I need a dynamic, Rails generated string within my JavaScript, for example translation strings and URLs. Translations are nicely solved using babilu but I'm still stuck on the generation ...

Ruby On Rails: Testing deletes tables

Hi there! I'm creating an application in RoR and I'm implementing unit testing in all my models. When I run every test on his own (by running ruby test/unit/some_test.rb) all tests are successful. But when I run all tests together (by running rake test:units) some tables from both databases (development e test) are deleted. I'm using...

Running scripts after object creation in Ruby on Rails

Hi all, I'd like to run a script that does some evaluation of user-entered data after it is successfully created. I have a model representing the data, but how do I specify that the model class should execute function X after an instance is successfully created? Part 2: would it be more appropriate to put the code I want to execute in ...

Problem generating pdfs with acts_as_flying_saucer

hi all. I'm using the rails plugin acts_as_flying_saucer to generate a pdf, but the pdf doesn't work: i can save it ok, but when i try to open it i get this error message: Unable to open document File type SOR File (text/plain) is not supported Here's my set up. I'm using rails 2.3.4 and the latest version of the acts_as_flying_sau...

mongodb gridfs carrierwave or joint or other ?

i want to store all my assets in mongo gridfs. i was trying to get carrierwave setup with mongomapper and gridfs but seems carrierwave supports mongoid now instead. I need to be able to save different size versions / cropped versions of an image so thats why i was going to use carrierwave. Currently its set up to store on file ...

Trying to find online users in rails

I am using the active record store to keep sessions in the database. Is there anyway to get the user_id from the session stored in the database? In my application im adding the user_id to a session when a user logs in using session[:user_id] = @user.id. Does doing this also update the session in the database with :user_id?. Thanks for an...

Problems with reflection within Rails

I have a Rails app representing a card game. There are several different types of card, and a few expansions for the game, each providing more cards. So I'm using a single cards table and STI, with each expansion having a models subdirectory and appropriately-named module. Like this: app/models - card.rb + base_game - foo.rb - cla...

Serving up files with Rails... I want access control but don't want to hog the rails process

I'm currently using send_data File.new(filename, 'rb').read, :type => content_type, :disposition => 'inline' To serve up uploaded files, which are stored outside the public directory. Of course, I don't want files to be globally accessible, so I'm not sure I want to bypass Rails in the usual way by putting the file into public. I woul...

Learning Ruby On Rails

I want to learn Ruby on Rails. I've done some work with various java frameworks but I can no longer ignore everyone RoR craze. I did some looking around and found that a lot of people recommend Agile Web Development with Rails as a good starting point. Would you agree? I was looking on the site for it (http://pragprog.com/titles/rail...

Rails subset select always returns true

First: Sorry for the ambiguous question, I'm not fully versed on Rails parlance yet. I am trying to search a dataset for a value. If the dataset contains the value, I'd like the app to do something. If it doesn't, the app needs to do something else. The data breaks down like this: I have affiliates and users, each with a HABTM relati...

Rails: fields_for only one object

I've got a model Product in my Rails application, its attributes can be edited, and I want to let user comment every change he makes (a comment can be blank, though). So, Product has_many :comments, it accepts_nested_attributes_for :comments and rejects it if the comment is blank. Hence, the edit form for Product is a multi-model form. ...