ruby-on-rails

How to always set a value for account-scope in Rails?

Hi, I'm working on a multi-user, multi-account App where 1 account can have n users. It is very important that every user can only access info from its account. My approach is to add an account_id to every model in the DB and than add a filter in every controller to only select objects with the current account_id. I will use the authori...

Module name scopes in routing

I have an intranet application with several modules, I want them to separate when routing. For example: http://intranet/calendar/... http://intranet/site_admin/... http://intranet/tasks/... Each of module can have many or single controller. How to write such routes? ...

Open Source Web Frameworks : Security

How secure are popular open source web frameworks? I am particularly interested in popular frameworks like Rails and DJango. If I am building a site which is going to do heavy e-commerce, is it Ok to use frameworks like DJango and Satchmo? Is security compromised because their open architecture ? I know being OS does not mean being...

Shortcuts in ActiveRecord?

Are there any shortcuts in Rails' ActiveRecord that enables you to search by value of a field? For instance, let's say I have a 'user' who can be active or inactive. Is there a nice way of doing User.active? or do I need to do User.find_by_active(1) Does this also apply to fields that may have many different values, such as a state co...

Testing a sessions decorator lib in ruby on rails with rspec

I have this code in lib/user_session.rb Its used by one of my controllers via include UserSession. How can I test it? I've added tests in spec/lib/user_session.rb but the code relies on the session which I'm not sure how to mock. module UserSession def viewed session[:viewed] ||= Array.new return session[:viewed] end ...

Is it valid to make Ruby Gems an analogy to Java JARs?

I believe I have put the question quite clearly and in a concise manner. Why do I ask? I am to explain Ruby on Rails framework to students and this requires me to make some analogies to the Java world (as the course is quite Java-centric). I have no hands-on experience with Ruby on Rails but I sense the Gem/Jar analogy is a valid one. ...

javascript in a rails :url parameter

I want to create a drop_receiving_element where the :url contains javascript. Currently I just created a helper function and hard-coded the element in like so: def create_classification_droppable(droppable_id, classification) "<script type='text/javascript'> //<![CDATA[ Droppables.add('#{droppable_id}', {accept:'lead', onDr...

want email from my server (postfix) to an email address on my domain to be delivered to google apps

I have google apps for receiving email. I get inquiries from people on info@[my-domain.com], which email is hosted on google. Sometimes, I want my rails set-up to send emails from my own server, and that works fine. But when I want to send to an email address on my own domain, such as [email protected], postfix sees the my-domain.com...

validates_presence_of not working properly...how to debug?

In my Review model, I have the following: class Review < ActiveRecord::Base belongs_to :vendor belongs_to :user has_many :votes validates_presence_of :summary end I submit a new entry as follows in the URL: vendors/9/reviews/new The new.html.erb contains a form as follows: <%= error_messages_for 'review' %> <h1>New rev...

Partial SSL in rails

Hi all, I'm looking to do a partial SSL site in rails. I basically want to protect the user actions behind SSL, but nothing else. Anyone know of a plugin or gem that makes this simple and efficient? ...

Shoulda, Rails Tests , and Autotest

I'm trying to model my tests after the great work that the Thougtbot guys have done. They seem to use the test framework built into Rails Shoulda. Great. I have been hearing a lot about Autotest - that its magical-ness should make things easier.... I expected that things would 'just work' if I installed it. My rake test:units already a...

how do I check if a 'Review' has already been written by a given @current_user?

Hello! For my model Vendor: :has_many Review And Each User: :has_many Review And Each Review: :belongs_to Vendor :belongs_to User So. I don't one a User to be able to write more than one Review, so I want to do a check on the vendors/:vendorId URL which is the "show" action, and have a way to make the "Write Review" button di...

how to set up restful_authentication email activation using gmail SMTP?

Hi, I have installed restful_authentcation from technoweenie with activation, and so I see the generated UserMailer < ActionMailer::Base. However, the instructions don't include how to set it up to work with Google SMTP. I am guessing that environments/development.rb needs to have the SMTP settings, but still not sure given Google (vi...

breakpointer not available in scripts directory in ruby on rails

Hi, I am a ruby on rails newbie. In my app i created using scaffold, breakpointer is not there under scripts directory. When i copied breakpointer from somewhere and put under scripts directory, it was giving an error. Any pointers on this will be great.. Thanks, Ayyappa ...

Is it possible to have validations for basic_model (couchdb) in Ruby on Rails?

Hi, is it possible to use validations like: class Post < ActiveRecord::Base validates_presence_of :name, :title validates_length_of :title, :minimum => 5 end with basic_model? I tried reading the source, but I couldn't find anything there. Are those validates_ available for other model types, or only ActiveRecord::Base? Thank...

How do I create/maintain a valid reference to a particular object in an ActiveRecord association?

Using ActiveRecord, I have an object, Client, that zero or more Users (i.e. via a has_many association). Client also has a 'primary_contact' attribute that can be manually set, but always has to point to one of the associated users. I.e. primary_contact can only be blank if there are no associated users. What's the best way to impleme...

Rails has_many association count child rows...

What is the "rails way" to efficiently grab all rows of a parent table along with a count of the number of children each row has? I don't want to use counter_cache as I want to run these counts based on some time conditions. The cliche blog example: Table of articles. Each article has 0 or more comments. I want to be able to pull how ...

i need to update the current time in a sql query.

Usage of Time.now or Time.now.to_s or Time.now.to_datetime is throwing error. Usage of Date.today doesn't help as it stores the date with time as 12.00 AM and not the current time stamp. Please help me in resolving this issue. ...

MySQL / Rails Performance: One table, many rows vs. many tables, less rows?

Hi, In my Rails App I've several models dealing with assets (attachments, pictures, logos etc.). I'm using attachment_fu and so far I have 3 different tables for storing the information in my MySQL DB. I'm wondering if it makes a difference in the performance if I used STI and put all the information in just 1 table, using a type colum...

TypeError Conversion on has_many relationship

I have a couple of objects in a Rails app ("Ticket", and "Comment") class Ticket < ActiveRecord::Base has_many :attributes has_many :comments end class Comment < ActiveRecord::Base belongs_to :ticket belongs_to :user end with the following schema: create_table "comments", :force => true do |t| t.integer "ticket_id" ...