ruby-on-rails

after_create :create a new line in DB

Hey guys I was wondering if anyone could help me with an issue im having, basically id like to have Account.create after a PayPal notification is received, There is a simple cart model which corresponds to line_items within the cart so add_account_to_market would look like this in pseudo code def add_account_to_market if status == "...

Rails, using ActiveRecord to find all rows matching a parent row attribute

I have a class Foo which has_many Bars. Foo has an attribute, some_id. I want to Retrieve all Bar instances where the Foo has some_id = N. In SQL this translates into something like: select * from bar inner join foo on foo.id = bar.foo_id WHERE foo.some_id = N ...

a better way to initialize database ONCE when rail server starts

i would like to initialize database the first time the server is started, that involve calling a class method. Given the class name is: Product At first i put an .rb file config\initializers\init.rb as it gets automatically called. Everything works ok, until the database is deleted, and i am trying to do rake db:migrate. rake db:migrate...

rails how do i redirect all the routing error to the root url of the application

if somebody type URL/frewfrefew, he gets a routing error. how do i get this invalids routes to point to the main page of the application in Rails. thnaks ...

What Web Hosting Service do I use for JRuby on Rails?

I'm developing a website with JRuby on Rails because I need some Java functionality server-side. I figure to deploy it, I will need to use a hosting service that supports JSP. Am I right and is that all I need? Or is there something else I will need to deploy my site? How would I go about doing this? ...

Getting session authenticity token via ajax (rails, jquery)

Hi folks, I wish to authenticate a user without having the page reloaded, and having the user submit a given form. However, the problem that I immediately run into here is that the authenticity token typically gets set when the page is reloaded. I need the authenticity token for the form submission, but i do not have it yet because t...

'script/console test' with spork and rspec not loading the whole environment?

I'm trying to load up console to interact with some of my rspec mocking helpers. I expected that running script/console test would load an env similar to when I run spec. However, this doesn't appear to be the case. It looks like spec_helper is never loaded. Or, if it is, it's not actually running through the logic because spork has poll...

Fetching only the first record in the table (via the view) without changing controller?

I am trying to only fetch the first record in my table for display. I am creating a site where a user can upload multiple images and attach to a post but I only want to display the first image view for each post. For further clarification posts belong_to projects. So when you are on the projects show page you see multiple posts. In thi...

Making Authlogic 'not remember me'

I want my user session to end when the user closes the browser. But authlogic seems to remember the session even when a new browser is opened. I have tried setting @user_session.remember_me = false but that doesn't help. I drilled down to the save_cookie method which is indeed saving the cookie with :expires => nil. Am I right in assumin...

in rails what is the difference between development mode and production mode?

Currently, I am using the Development mode for my application, but I don't know if I should use the Production mode. If it is the case, how do i transfer all my data to the Production mode? Will there be a risk of introducing bugs in this process? ...

What is step to create component in RoR

Hi any one tell me how can i create a component in RoR ...

Ruby GPX file parser

Advise what can parse GPX file in Ruby? I tried: http://github.com/dougfales/gpx - it does not work with Ruby Enterprise Edition (http://github.com/dougfales/gpx/issues # issue / 1) I would not like to write a parser ...

Polymorphic association inserts 0 instead of raising error when column is misconfigured as Integer

Here's one that stumped me for a while, though in retrospect it should have been obvious. I was getting the error message NoMethodError: undefined method `constantize' for 0:Fixnum when accessing a model through a polymorphic association. Turns out the table on the belongs_to side of the association had an integer type column instead...

Route alias, is it possible?

I have a Vehicle model: Routes: map.resources :vehicles, :has_many => :suppliers Everything works great, but Vehicle has a boolean attribute is_truck. I want to make an Alias so I can get the same resources filtering only trucks, I tried with: Routes: map.trucks '/trucks', :controller => :vehicles, :action => :index, :is_truck => t...

how to make a web-gallery with RoR?

hello, Im a newbie RoR kid, and I'm trying to make a web gallery app just like the onyx http://www.hulihanapplications.com/projects/onyx since it's outdated and i couldn't get it to work with my 2.3.8 rails' version. So, are plugins like paperclip or carrierwave any good for me to start with. Or should i take another route and writh the...

Associated models in Rails?

Hi Everyone, In my rails application I have two models called Kases and Notes. They work in the same way comments do with blog posts, I.e. each Kase entry can have multiple notes attached to it. I have got everything working, but for some reason I cannot get the destroy link to work for the Notes. I think I am overlooking something tha...

Rails and Prawn PDF - add current item ID to filename?

Hi Everyone, I have two PDFs that are made "on the fly" using Prawn PDF. The PDFs are called jobsheet.pdf and discharge.pdf - their URLs are: railsroot/kases/IDNO/jobsheet.pdf railsroot/kases/IDNO/discharge.pdf I am trying to work out how to automagically append the filename with the ID number: railsroot/kases/IDNO/jobsheet_IDNO.pd...

How do I use Haml in a view in my new plugin?

I'm creating a new plugin for a jruby on rails application that will eventually be turned into a gem. Inside my plugin I have controllers, helpers and views. For my views I'd like to use Haml. The problem is that I can't seem to get it to recognize that they are haml templates. Is it even possible to do this? Is there a way for a plugin ...

Getting list of states/events from a model that AASM

Hi, I successfully integrated the most recent AASM gem into an application, using it for the creation of a wizard. In my case I have a model order class Order < ActiveRecord::Base belongs_to :user has_one :billing_plan, :dependent => :destroy named_scope :with_user, ..... <snip> include AASM aasm_column :aasm_state aasm...

Rails: Problem with routes and special Action.

Hello! Sorry for this question but I can't find my error! In my Project I have my model called "team". A User can create a "team" or a "contest". The difference between this both is, that contest requires more data than a normal team. So I created the columns in my team table. Well... I also created a new view called create_contest.html....