ruby-on-rails

Rails setting OR conditions in validate_presence_of in a model?

In a rails model, is it possible to do something like class Example < ActiveRecord::Base #associations validates_presence_of :item_id, (:user_id OR :user_email) #functions end Where the model has 3 columns of :item_id, :user_id, and :user_email? I want the model to be valid as long as I have a :user_id or a :user_email. Id...

Rails form helper and RESTful routes

Hey guys, I have a form partial current setup like this to make new blog posts <% form_for([@current_user, @post]) do |f| %> This works great when editing a post, but when creating a new post I get the following error: undefined method `user_posts_path' for #<ActionView::Base:0x6158104> My routes are setup as follows: map.resour...

Rails 2.x http basic authentication

I'm trying to get basic http authentication working on my Rails app. I'm offering a simple REST interface served by a Rails server, only xml/json output. Every method needs authentication, so I put the authenticate filter in ApplicationController: class ApplicationController < ActionController::Base helper :all # include all helpers,...

JQuery LiveValidations with Rails

I am using this plugin: http://wiki.github.com/augustl/live-validations/ to check if the form field entered is valid or not. How do i disable the live validation for keypress and instead make it only fire when the submit button is clicked? ...

Class method or named_scope?

i would like to have your opinion in a project i am currently working on. class Product has_many :orders end class Order attr_accessor :deliverable # to contain temporary data on how many items can be delivered for this order belongs_to :product end somehow i want to have Order.all_deliverable that will calculate the Product...

Is there a variable in Rails that equates to the template that is being rendered?

I can do request.path_parameters['controller'] and request.path_parameters['action'], but is there anything like request.path_parameters['template'] so I can discern which template file (such as index.html.erb) is being rendered? I'm writing a method that automatically sets the body id to the template being rendered, for easy css manipu...

validates_associated not honoring :if

I'm totally blocked on this. See this pastie for sample code: http://pastie.org/990040 The first test will fail. The user model validates an associated address model, but is only supposed to do it if a flag is true. In practice it does it all the time. What is going on? ...

ruby on rails: bundles like django?

i wonder if ruby on rails have bundles, the ones similar in django? kind of a plugin that contains css, js, images, ruby code and everything for one feature. thanks ...

Creating an Admin directory in Rails

I've been developing the CMS backend for a website for a few weeks now. The idea is to craft everything in the backend first so that it can manage the database and information that will be displayed on the main website. As of now, I currently have all my code setup in the normal rails MVC structure. So the users admin is /users and vide...

Deploying to Heroku with sensitive setting information

I'm using GitHub for code and Heroku for the deployment platform for my rails app. I don't want to have sensitive data under Git. Such data include database file settings (database.yml) and some other files that have secret API keys. When I deploy to heroku, how can I deal with files that are not under revision control. When I use Cap...

Rails engines extending functionality

So I have an engine which defines some models and controllers. I want to be able to extend functionality of some models/controllers in my application (eg. adding methods) without loosing the original model/controller functionality from engine. Everywhere I read that you simply need to define controller with the same name in your applicat...

initializing variables in ActiveRecord's classes

How to initialize variables in ActiveRecord class? Variables here is the variables that are outside the scope of database such as: class Product attr_accessor :used end I want to initially assign @used initially to false, later if some person access the product, i will change @used to true First i thought of putting @used=false i...

Using wamp's Mysql for Ruby on Rails

Hi all, I am new to ROR. I have wamp all ready to go, I'd like to use its mysql for ROR so that I can access the database from phpmyadmin. How should I do that? Here is what I have in database.yml: development: adapter: mysql encoding: utf8 reconnect: false database: my_database pool: 5 username: root password: host: localhost port: ...

How many of you have gone from MySQL to Postgresql? Was it worth it?

I'm thinking about moving from MySQL to Postgres for Rails development and I just want to hear what other developers that made the move have to say about it. I'm looking for personal experiences, not a Mysql v Postgres shootout, just the pros and cons that you yourself have arrived at. Stuff that folks might not necessarily think. Fe...

Why does FastCGI not work well with Ruby on Rails?

It is said that FastCGI doesn't work well with Ruby on Rails deployment. Why is that? In previous experience, something either works quite well or it might be fundamentally wrong. So if FastCGI is a viable solution, why is it not reliable with RoR? Does FastCGI work well with most any language / frameworks? ...

accessing Ruby variable(from model or controller) in SASS

Is there a way to access Ruby variables in SASS or do I have to make a custom function for it? What I'm trying to do is to generate a stylesheet for each user so in the controller, I do something like: def show respond_to do |format| format.css{render :partial => "styles"} end end then in the view name _styles.haml I do this...

HAML indentation problem IF

This is my code: [email protected] do |a| -if @i%3 == 0 %ul %li=link_to a.name, a -@i += 1 I need the li to be inside the ul which is inside the if-statement. I can't do it because of the indentation. Can't I just tell the li to indent automatically? Thanks ...

Tell me how to use ActiveRecord#afeter_add

Hey,Guys! Now I hava a problem,how can I make the callback#after_add receive a reference to the join model in a has_many :through association? my code like this: class Emergency has_many :departments, :through => :eme_references, :after_add => Proc.new { |eme_reference| eme_reference.eme_flag = 1} end the attribute eme...

Formtastic, pre-modification of symbol

I have input/select on Formtastic form f.input :some_model_values, :as => :select The problem is i need to pre define :some_model_values. Because some users roles have to see all list, and some others not. How it can be done? Thanks. ...

How to prepare data from more tables for JqGrid in Rails app

Hello, I have a problem with prepare data for JqGrid. I have used this plugin http://www.2dconcept.com/jquery-grid-rails-plugin and I need table with data from more models. for example User model: has_one :profile has_many :users_roles has_many :roles, :through=>:users_roles and i need this data in jqGrid [user.login, user.profile....