ruby-on-rails

Heroku: Running imagemagick w/ paperclip

I have installed image magick on my mac os x computer and now I want to deploy it to heroku. I've installed the the paperclip plugin on heroku but I get this error when uploading an image: Paperclip::CommandNotFoundError I had this error before when I didn't have imagemagick instaledl on my computer before but now that I want to deplo...

Ruby/Rails - How to convert seconds to time?

I need to perform the following conversion: 0 -> 12.00AM 1800 -> 12.30AM 3600 -> 01.00AM ... 82800 -> 11.00PM 84600 -> 11.30PM I came up with this: (0..84600).step(1800){|n| puts "#{n.to_s} #{Time.at(n).strftime("%I:%M%p")}"} which gives me the wrong time, because Time.at(n) expects n to be number of seconds from epoch: 0 ...

Redirecting to a page from the Select Menu

I want to use a select menu to redirect to another page in Rails. I tried to add link_to to the select tag but it does not work. How can this be done? ...

Rails Device "Fingerprinting"

Is there any way or best practice around device fingerprinting for a rails app? In other words. Given that all cookies are blocked, is there any way, with a relatively good degree of certainty, who the person is before they log in? My assumption: IPs are unreliable for obvious reasons. ...

Rails - Adding a Include/JOINs to a query?

Hello, I have the following in my controller to obtain a project's team members: @project = Project.find(params[:project_id]) @teammembers = @project.permissions.includes(:user).joins(:user, :role).select("*") The problem here is that the user's table belongs_to the instance model. And the instance model has a name, which I want in @t...

Heroku: Rails 3 and rmagick

Hi, I'm seeing the following error when trying to upload a photo for cropping on heroku with the paperclip plugin. Paperclip::CommandNotFoundError I believe I've successfully install rmagick on a rails 3 instance with bamboo as the stack. Why am i seeing this error? has_attached_file :avatar, :styles => {:large => "600x600>",:small ...

In older versions of Rails, what are the methods to say, controller <--> view sharing methods?

I think in newer versions of Rails, there are ways to say, "share these methods between controllers and views" using something like controller.helper controller.helper_method (I am not sure if they are). But what if these methods are missing in older versions of Rails? How can you tell Rails to share methods between controllers and...

Rack rack.input variable getting truncated?

I wrote a piece of Rack Middleware to automatically unzip compressed request bodies. The code seems to be working just fine, but when I plug it into my rails app, I get a failure "Invalid JSON" from ActionController::ParamsParser. As a debugging mechanism, I'm writing both the zipped content, and the unzipped content to a file (to make...

JQuery UI Toggle

I am trying to get JQuery to give me the following setup. One listbox contains three options. One of these options, when clicked, will reveal a div. Either of the other two options reveal a second div. I am using JQuery UI/Toggle: http://jqueryui.com/demos/toggle/. For example: <%= javascript_include_tag "ui/jquery.effects.core.js", "ui...

What would cause an action in my Ruby on Rails controller to be called repeatedly?

Helllo. I'm diving into RoR and, after installing Paperclip and setting up my code to adapt to it, the new method in one of my controllers is causing a StackOverflow ;) . I'm running Rails 3.0 and Ruby 1.8.7. Can anyone guess or tell me what could be causing my new action to be called repeatedly? Here's the server output... Starte...

How do I configure Rails to output decimals to the correct precision in form fields?

I want to store currencies in my (sqlite and mysql) databases. I'm trying to use the decimal column type, with :scale => 2. This isn't behaving as expected. If I save a record with :rate => 10.50, it is stored in my sqlite db as 10.5. In addition, when I output the value in a form field, it is displayed as 10.5. I don't want to do hack...

TextMate js.erb: toggle <%= %>, <% %>

I'm using a js.erb template to render some jQuery. When editing an html.erb file in TextMate, I frequently use the convenient key combo, ctrl+>, to create and then toggle the following tags: <%= %> <% %> <%- -%> <%# %> This shortcut doesn't work by default when editing js.erb files. In the Bundle Editor, I found a snippet called "...

Rails 3 - HABTM not updating join table with <<

This is killing me... When trying to add a key to like so: category.site_ids << 1 category.save It does not save. But when overriding completely, it works: category.site_ids = [1] category.save What am I missing here? ...

Rails: InvalidAuthenticityToken while token is supplied

I'm trying to use an Java Applet for uploading files to my rails application. However I keep getting the following error and I can't figure out why: Processing CategoriesController#upload_image (for 127.0.0.1 at 2010-10-18 20:32:54) [POST] Parameters: {"partitionIndex"=>"0", "fileId"=>"8278320", "lastModified"=>"2010-09-18T14:31:...

Ruby on Rails, Posting Variables

I'm very new to rails so hopefully this should be a quick fix. I'm writing an application that searches a database and reloads the page displaying the desired results. In rails how does one save a input into a text_field and post it so that it can be retrieved and used in the query for retrieving data. My view: ...

Design: Custom access control (restrict page access based on some criteria)

Although I will be using Ruby on Rails, this is a general questions about the best way to model a database and design a custom access control system for a CMS. So it does not matter what language/db. I would be happy to hear input from all experts. My problem: I am in the early process of developing an online tutorial system for a local...

multiple joins in rails

I am building a recipe app where a user can view recipes, list ingredients, get a shopping list, etc. etc. Each Recipe is made of steps, each step has ingredients, and each ingredient has a grocery. I was quite sure that the way to create these links was through the models, so my models look like this class Recipe < ActiveRecord::Bas...

Using Curl to Post to a Restful Rails Application

Could someone enlighten me on how to upload files the RESTful way to a Rails application? I experimented with curl to simulate uploading an image to a rails controller. At first I got authenticity token errors and so disabled them, and then tried curl -F "[email protected]" http://localhost:3000/photos/create but this didn't ...

How to test view page(paginate) with rspec-rails2?

rails 3 rspec-rails 2 in controller def index @users = User.paginate :page => params[:page],:per_pae => 5 end in view User list <% @users.each do |user|% <%= user.name %> <% end %> <%= will_paginate @users %> Now I use rspec-rails 2 to test view. require 'spec_helper' describe "/users/index.html....

How to give user live feedback for Rails form

I need to make a Rails form that responds back to the user live as they input fields. Specifically, the user will need to input four decimal fields representing data from some tests our company runs. The problem is that the testers often input incorrectly (leave out a digit, or hit a '4' instead of a '1', etc). This is easy to check, ...