ruby-on-rails

Making an if statement inside a hash in a model

Hi guys, i am trying to display all the residents on a pdf and their dependents, but the dependents doesn't have a stand they are identified by the foreign key user_id of the resident. e.g resident1.id = 5 --- dependent3.user_id = 5 mean dependent3 belongs to resident1, and therefore if i want to display the dependent stand what should i...

how to handle multiple models in a rails form

http://weblog.rubyonrails.org/2009/1/26/nested-model-forms This post helped in learning how to handle multiple models in a rails form. It works as long as the models are nested. what if they are not? lets say, I have a form, where the user fills personal details, address details and a bunch of checkboxes specifying her interests. Ther...

Where is the syntax error?

roles = Role.find_all_by_simulation_id(session[:sim_id]) forum_posts = Post.find(:all, :conditions => ["role_id = ? AND created_at > ?", roles.map(&:id), session[:last_login]]) Error: SQLite3::SQLException: near ",": syntax error: SELECT * FROM "posts" WHERE (role_id = 1,2,3,4 AND created_at > '2009-05-21 11:54:52') ...

Changing the look of textfields

How do I change my textfields so they look more like the Twitter login textfields or even the Title textfield for Stackoverflow when you post a new question. I currently just use: <%= text_field_tag 'name', @name, :size => 30 %> ...

DB connection problem in production

I have a separate DB for one model in my application and in development mode the connection is working properly, in production however it isn't. production: adapter: mysql host: myhost username: root password: database: production_db users_production: adapter: mysql host: myhost username: root password: database: ot...

Rails: Making this query database-agnostic...?

I have these two lines in my model, written for PostgreSQL: named_scope :by_month, lambda { |month| { :conditions => ["EXTRACT(MONTH FROM recorded_on) = ?", month] }} named_scope :by_year, lambda { |year| { :conditions => ["EXTRACT(YEAR FROM recorded_on) = ?", year] }} I'm running PostgreSQL in production, but I'm developing with SQLi...

Overwriting/Adding an ActiveRecord association dynamically using a singleton class

The business logic is this: Users are in a Boat through a join table, I guess let's call that model a Ticket. But when a User instance wants to check who else is on the boat, there's a condition that asks if that user has permission see everyone on the Boat, or just certain people on the Boat. If a User can see everyone, the normal dea...

What are your favourite Rubygems?

Possible Duplicate: What are the "Must Have" Ruby Gems There are a load of great Rubygems out there that do some amazing things. In fact, I sometimes wonder what I'd do without Rubygems - they certainly give a load of appeal to Ruby and Rails. What are you favorites, and what would you recommend to install? ...

Best practices for multiple models in rails from - nested / non-nested, and validations

Note: Posting this as a separate question as per Brian's comment (from http://stackoverflow.com/questions/892624/how-to-handle-multiple-models-in-a-rails-form) I'm trying to learn the best way to handle multiple models in a single rails form, when the models are both nested and non-nested. For the nested ones, I found these two tutoria...

Destroy cookies in rails, facebook connect, facebooker plugin

So I have sort of a weird situation going on. I am using the Facebooker plugin for rails where I want users to be able to login and logout with their facebook profiles. However, once users logout, if I refresh the page, it logs them back in. This is only when users log in with facebook connect. I think the problem is that a rogue coo...

2 buttons, 1 form

Hello, I have a simple form that looks like so <% remote_form_for post, :url => post_path(post), :method => :put do |f| -%> <%= f.submit "Approve" %> <%= f.submit "Deny" %> <% end -%> Which renders <input type="submit" value="Approve" name="commit"/> <input type="submit" value="Deny" name="commit"/> In my controller I have the ...

What can I use to host a Rails site on Windows?

Okay, before you guys go nuts -- this is just a small site, temporary setup. Right now I'm having some internal folks remote into the server and use the site through webrick via the dev command: ruby script/server. Not exactly ideal. I'm just starting Rails dev and I want to know a better way to handle hosting on a Windows Pro box. A...

Why can't Rails work with mod_ruby?

I'm sorry if this sounds like a stupid question, because it seems to be one of those "no duh" things, but can someone explain to me why Rails needs its own server (Mongrel, WEBrick, mod_rails, etc) and can't simply use mod_ruby? ...

What is a good method to bypass authentication and/or authorization in development mode?

I have several actions that are protected by filters that check for logged_in? and admin? and spit out 401 or 403 errors respectively if the tests fail. What's a good way of getting around these filters in development mode only so I can test out my app? I can't go through the actual login procedure because it relies on infrastructure I...

Is there a replacement for Beast for Ruby on Rails

An open source project called Beast implemented a forum in about 500 lines of Ruby on Rails code. The project seems to have fallen silent (http://beast.caboo.se/). Is there an open source project that replaces beast and is compatible with the database schema defined for Beast? I have used Beast to sponsor a forum and would like to upgrad...

Rails: How do I use helpers in a separate class in lib

I'm happened to write create one file in lib folder and I want to use TextHelper in that file. How can I make Texthelper available? Suggestions appreciated, Thanks, ...

Authlogic - Logout not working on production but working in dev?

I have only just started to investigate... but thought I would throw this to the community as well. I am building an app using Authlogic for authentication. The auth part is basically straight off the authlogic tutorials... My logoff button works in dev, destroying the session and giving the flash on the root_url. However, on productio...

What is the best way to have long string literals in Javascript?

Possible Duplicate: Multiline strings in Javascript In Ruby you can do something like this temp = <<-SQLCODE select * from users SQLCODE This way you have very long string literals in your code without have to escape lots of characters. Is there something similar in JavaScript? Currently I have javascript code like this, an...

Rails design/coding question

We have a web app which serves typical social content(blogs/forums/streams etc). All the content is optionally marked with a city. I.e. if a blog post is specific to New York, it will be marked so. The task is to show only city specific information(all over the site) if user has set city view preference and show everything to all oth...

Rails - fragment cache not expiring

This one has me stumped. I have a view with a cached fragment: - cache :key=>"news" do %h2 News - etc I have a sweeper that uses: def expire_home_cache puts "expire_home_cache" expire_fragment(:key => "news") end The sweeper is called as I can see "expire_home_cache" in the console output. But the fragment is not...