ruby-on-rails

how does one load a model with a custom name in to a controller

I'm trying to access a model for global system settings. It should be loaded in almost every controller. The problem is I can't find any help on getting rails to load the dam thing. If this helps, the model is called Config and has two columns; 'key' and 'value' I come from a background in PHP. I remember codeigniter could load models ...

Ruby on Rails add models for existing plugin?

Hi, I am new to Ruby On Rails, and currently trying to modify an existing (uncomplete) plugin from github. Things went smoothly until I am trying to add new models to this plugin. I know script/generate model, and script/generate plugin. But how to add models into a plugin without regenerate the whole plugin? I don't want rewrite the pl...

How do I switch JavaScript libraries in Rails 3

I didn't skip prototype when I began my new project and I want to move to JQuery. What is the best way to switch libraries? ...

Reading an uploaded file into a File object in a controller method-"can't convert Tempfile into String"

So Im trying to implement a file upload functionality where when a user uploads a file, I can read that into a File object and process it accordingly: def create name = params[:upload]['datafile'].original_filename directory = "public/data" # create the file path path = File.join(directory, name) # read the file Fil...

Not a beginner, not yet intermediate

I consider myself a very enthusiastic amateur, no longer a beginner but unable to write code that goes beyond the simple examples found in most books. As often recommended, I've chosen a small project I'm passionate about and started hacking away on it, knowing that many concepts are still over my head. Given my past history, I'm concern...

Mongoid with Machinist

I am using machinist and mongoid. How can I generate blueprint for embeds_many association. Mongoid embeds_many association embeds the hash of array. So I just started like this: User.blueprint do address { :address1 => "address", :address2 => 'next address'} end Any Ideas? ...

How do I chomp a redirect url in rails? I'm having trouble with Twitter's OAuth

I'm having a pretty bizarre and frustrating problem with Twitter's API. The oauth process is working just fine locally but once I put the site on heroku it automatically adds the url of the testing server and redirects to a broken page. This is the code: def oauth oauth = Twitter::OAuth.new('*','*') request_token = oauth.requ...

Strange Rails 2 Routing Question

I saw this in a rails 2 vs 3 comparison pdf lecture and I'm not sure what's going on with the preview and archived flags. post.resources :comments, :member => { :preview => :post }, :collection => { :archived => :get } Any ideas? ...

Ruby on Rails app on Google App Engine

Hey there! Can anyone point me how I could deploy my rails app to GAE? I've been reading about it, but it seems to be a fairly complicated task. I tried with the google-appengine gem, but its not a piece of cake either. Has there been any progress with the DataMapper adapter or I'll need to make changes to my models? I was hoping to s...

can't dup NilClass - Error

I am stuck in this error for quite sometime now and have hit a dead end. I get this totally unhelpful error can't dup NilClass This is the situation. I have one class which is in a relationship with another. Say class Parent end class Child < Parent unloadable :has_many :parents, :foreign_key => "child" end The err...

Ruby, SSLSockets, and Apple's Enhanced APN message format

I'm trying to implement support for Apple's enhanced Push Notification message format in my Rails app, and am having some frustrating problems. I clearly don't understand sockets as much as I thought I did. My main problem is that if I send all messages correctly, my code hangs, because socket.read will block until I receive a message. ...

"Ago" date/time functions in Ruby/Rails

Hi - I was wondering, if theres a way in rails to calculate time stamp like - half a minute ago, 2 minute ago, 1 day ego etc. Something like twitter real time date stamp. I want to know if ruby/rails has a pre-built function for such date-time conversion?? ...

Is it possible to use modify nginx config file and use X-Accel-Redirect on Heroku?

Reading this article on nginx website, I'm interested in using X-Accel-Redirect header in the way that Apache or Lighttpd users might use the X-Sendfile header to help with the serving of large files. Most tutorials I've found require you to modify the nginx config file. Can I modify the nginx config file on Heroku and if so, how? ...

help with ruby on rails

I have installed Ruby. When I start the Mongreal server I get this error message the program cant start because msvcrt-ruby18.dll is missing I even downloaded the file msvcrt-ruby18.dll, but no use I googled it, but cannot solve the problem ...

How do I use this Ruby code?

I found this Ruby code to help use the Imageshack API on CodeSnippets. I'm new to Ruby on Rails, so I know how to use models, views and controllers generally, but I'm not sure how I just use this code. Would it be a module? Thanks for reading. Usage: pic_online = ShackMirror.new(local_path_of_pic) pic_online.url # => retu...

mongodb find in embedded document hash mongomapper

hi I have a menu class and that have many menu_items and a menu_item class that is embedded docuemnt. I can get a specific menu like menu = Menu.find_by_name("menu 1") then i want to find and update or create the menu_item that matches a specific category id. I want to create the menu item if category id is not found in menu items...

How do I use options for in_place_editing in my view ?

I want to change how the in_place_editing view looks like. I want to change the button text and other view related things in the in_place_editing plugin I am trying with this code <%= in_place_editor_field :contact,:address_line1,:saving_text =>"Update"%> But nothing is getting changed. How else can I pass options to in_place_editor...

ActiveRecord gives 'no such column' SQL error for simple has_many association

This is driving me insane! This code used to work fine, but as of a few weeks ago it stopped working, and I can't work out why. Basically a Game has many Patches. The error occurs in my PatchesController, but its reproducible in the rails console like this: first_game = Game.find(:first) first_game.patches As soon as I use the patches...

When to include format inside file name for view templates

I have two identical controllers Submissions and Activities, both using the default resource mapping for routes. I want to use some RJS for the show method, both of which can be accessed as such as a GET request: /submissions/1.js /activities/1.js I have show.rjs inside their respective view folders like so: ../submissions/show.rjs ....

Rails Custom Functions EDIT: Update from inside the controller.

Right now I have this social media app, where I'm implementing ratings on users per category, What i want to do it's: Whenever an user casts a vote on an article, it will grab all the votes on the article and make an average of the score/votes and insert that value into another model that i have (User Category Rating), now my question i...