ruby-on-rails

Variable passing to find function in rails 2

I am new to Rails. I have following construction. Mainmenu in my project has many submenus. In defining @submenu is everything ok, but in finding @mainmenu not. The output is: Couldn't find Mainmenu without an ID @submenu = Submenu.find(params[:submenu_id]) @mainmenu = Mainmenu.find(params[:id => @submenu.mainmenu_id]) How can i defin...

Capistrano Deploy Wipes Database?

I've managed to deploy my app to production using Capistrano, but I don't understand how to deal with my database. I'm using subversion and passenger. When I run cap deploy, the new deployment starts everything fresh. It wipes out the data that was added to the database. Obviously, there must be a solution, but I'm very surprised not...

ASP.NET MVC AjaxHelpers recommended usage

It seems all the examples I come across specifiy an UpdateTargetId to render out the HTML content of the Ajax response. This is quite a bit different than how it's done in the Rails world, where the response content contains JavaScript code which manipulates the page. The Rails convention seems more powerful. What's the recommended usag...

Asterisk Out Password in HTML (using Ruby on Rails)

I'm a newby at web programming, and even newer to ruby on rails. What is the best way of asterisking out or "hiding" a new password entered by a user? ...

How to save an array of models in rails

Hello! I've been googling this for a while, but haven't found any answers I've got models called answers, surveys, questions. Now in a survey, there can be up to 200 questions and so one survey can generate up to 200 answer-models in a page. The question is: How can I save the array of answers I have in a single db-action and not ite...

Bidirectional relationships in ActiveRecord

I want a "friend" relationship, as in "social site friends", which means: if I'm friending you you invariably friend me. If I remove you from friends, you do that, too. (well, you get the idea). Currently this is done with duplicate relations and an observer to add/remove the second (more correctly, "other") relation when the first gets...

How to make flexible models and associations

Hi, I am trying to design a very flexible model like google docs survey. It's a bulletin board post model. And admin(or site builder) can add boards freely. But instead of fixed columns, admin can define additional columns. So the post model can be used for many other purposes. I have currently 2 models - board and post. A board has m...

Rails rendering a new object as an edit?

I have an application where I'm creating a new object via a "new" action. Rails is using the correct controller action, and also rendering out the new form correctly. However, the path for the form is coming up with an Id for an edit which is breaking things. The form tag is just: <% form_for @issue do |f| etc Any ideas as to why ...

Ruby on Rails: Nested Attributes, belongs_to relation

Hello guys, I hope you can help me. I have a User entity that has a Current Location field (city and country). To old this info I created an entity called Location which has_many Users. I'm not entirely sure if I should put in the User model "has_one" or "belongs_to", but for what I read if I wanted it to have the foreign key of the lo...

How do you plan your Rails app?

I'm starting a Rails app for a customer and am considering either creating a mind map or jumping straight to a Cucumber specification. How do you plan your Rails app? As an additional question, say you also start with Cucumber, at which point would you write Unit tests? Before satisfying the specifications? ...

performance/ruby/rails/db question

I'm creating an online bookmaker odds comparison site for soccer and I'm wondering how to calculate the best odds in Ruby/Rails. I have two models: fixture and odds Fixture has home and away teams, and odds model has bookmaker ID, home odds, draw odds and away odds. I have selections which just stores the selected fixtures/teams in th...

sql charateristic function for avg dates

I have a query which I use to grab specific dates and a price for the date, but now I'd like to use something similar to grab the avg prices for particular days of the week. Here's my current query which works for specific dates to pull from a table called availables: SELECT rooms.name, rooms.roomtype, rooms.id, max(availables.updated_...

has_many through self referential association

I want to (as an example) create a has_many association to all posts by friends of a person, something like has_many :remote_posts to give me something like person > friends > person > posts. ..here is how I would go about it script/generate model post title:string person_id:integer script/generate model friendship person_id:integer f...

Rails 2 + SQLite 3 - can ID field be zero?

My problem: I'm writing a flex frontend to a rails app, and I'm having problems in managing NULL database values.. so to avoid problems I just don't allow NULL. Now, for foreign keys, would 0 be fine? No chance that a record be assigned ID 0, right? Maybe I could somehow tell rails to skip foreign key updates if input is 0.. ...

request.format returning */*

Good afternoon, I'm currently developing an API for my application on RoR As an example, I created some XML, loaded with all the info I need to create the object, let's say a Person, and using Curl I submitted it to my application I'm able to call exactly the create action I want from the controller and the hash params of the object a...

undefined method `user_sessions_path' for #<ActionView::Base:0xdb3158>

I'm getting this error that's driving me up the wall. I don't see what's going on... I've followed instructions to the T and it's still complaining - help please!! I've got extracts of the error message, controller file, login page and routes file. Error message NoMethodError in User_sessions#new Showing app/views/user_sessions/new.h...

Ruby on rails deployment with Vlad on windows.

Hi, I am having a problem with Vlad on windows. After calling rake vlad:deploy I am getting the following: uninitialized constant Fcntl::F_SETFD After googling for a while I figured out that there is problem with open4 gem that is not suitable for Windows and I should use popen4 gem instead. I installed it but nothing has changed. Ho...

Logging Search Results in a Rails Application

We're interested in logging and computing the number of times an item comes up in search or on a list page. With 50k unique visitors a day, we're expecting we could produce 3-4 million 'impressions' per day, which isn't a terribly high amount, but one we'd like to architect well. We don't need to read this data in real time, but woul...

Share session data between Rails and PHP

I have a Rails application that uses ActiveRecordStore for sessions. I need a PHP application running on a subdomain to share the session. I have updated the environment to allow session cookies to be accessed across subdomains, but I don't know what the php application will have to do to access the session data. Please could someone he...

custom before/after hooks in rails for non standard actions?

I have a controller with some non standard actions, like admin, moderate, etc. I tried using the hook before_admin it that didn't work. Is it possible to use these hooks for my custom actions? Sorry for the lack of clarity. Say I have something that I want to happen before saving..it's easy to just do a before_save :do_whatever inside t...