ruby-on-rails3

Random jokes in a skit (activerecord)

I am working on populating my database with test data using populate.rake: Repertoire.includes(:jokes).each do |r| @jokes = r.jokes Skit.populate 8..12 do |skit| skit.joke_id = @jokes[rand(@jokes.count)].id end end This is giving me a RuntimeError: Called id for nil. How can I populate a skit with random jokes? ...

Overloading association methods

Does anyone know if there is a way to overload an association accessor method and not the setter? For example class Bar has_many :users def users 'foo' end end a = Bar.new a.users # => 'foo' a.users << bob => [bob] Hope that makes sense. ...

Internal messaging in Rails

I'm using this tutorial to get internal messages working on my site: http://www.novawave.net/public/rails_messaging_tutorial.html But, since my latest upgrade to Rails 3, I'm getting this error: NoMethodError in MsgController#sendmsg undefined method `each' for #<String:0xcc8acc0> Application trace: app/models/message.rb:16:in `prep...

New validator class introduced in lib directory is not recognised and throws error

Unknown validator: 'email_format' Rails.root: /home/saran/work_space/rails_apps/test_app Application Trace | Framework Trace | Full Trace app/models/user.rb:2 app/controllers/user_controller.rb:5:in `create' my user model file as below:- class User < ActiveRecord::Base validates :email, :presence => true, :uniqueness => true, ...

where does validates method reside in ActiveRecord::Base ?

Hi all, I understand that the documentation to the Rails 3.0.0 validates method is in ActiveModel::Validations::ClassMethods http://www.railsapi.com/doc/rails-v3.0.0/classes/ActiveModel/Validations/ClassMethods.html#M003721 I was wondering then, how a class that inherits from ActiveRecord::Base has the validates method? For example, i...

Page Caching in rails 3

Is there is any good page caching plugins available for rails 3. I had used page_cache_fu till now. When I shifted to rails 3 its showing to_prepare method error? ...

Rails date and time is off on my local machine in created_at

ok this is very strange. My computers clock is correct, but whenever I output a created_at field in the database and format it, the day/time are off my several hours... Is there some Rails 3 localhost type setting? ...

Any links or pointers where I can learn about various data types available in ruby(on rails) ?

Some datatypes which I commonly use are string ,integer while creating models *text_field, text_area and password_field* while creating forms inside views. Data types to use with models are my first priority . ...

How to comment lines in rails html.erb files ?

Am a newbie to rails , please let me know the way to comment out a single line and also to comment out a block of lines in *.html.erb files. ...

Rails - HowTo - Handle Users w/o Images

Hello, I just installed paper_clip to allow user's to upload a profile pic which can be displayed easily with: <%= image_tag @user.profile_pic.url %> What I'm curious about now is how to handle user's that don't have a profile_pic uploaded.. How to show a standard site user image (generic) Should I make a helper? something like show...

Rails - truncate - is not behaving--- Using a var returned from the model

Here is the truncate code I'm using: <%= truncate(teammember.user.full_name, :length => 8)%> teammember.user.full_name returns names like: - Steve Jobs - Larry Oracle - James Bond - Dhandar Kentavolv Butall the truncate is doing is returning: - Steve Jobs... - Larry Oracle... - James Bond... - Dhandar Kentavolv... The user.f...

Rails: category and subcategory tree

Hi I am new to rails ... I am trying to make a category and subcategory tree in rails...can you please guide me.. my schema is as follows: create_table "categories", :force => true do |t| t.string "name", :null => false t.string "aka", :null => false t.integer "parent" end ...

Rails 3- Understanding the Controller/Routes relationship

Hello, I have a model photo which allows me to load URLs like /photos /photos/2 /photos/2/edit Edit allows the user to change the image, but I want a different kind of edit for permission type stuff specific to the app I'm building, which would look like: /photos/2/updatesettings So in the photos controller I added "def updatese...

rails user-ip from within the model?

I'm wondering if there's a more direct way to get and record a users IP in the model itself. I've been doing it from the controller but I noticed using the rakismet gem it mentions doing everything from within the model, but not the IP specifically. http://github.com/joshfrench/rakismet Currently I'm doing this, just before I save fro...

One model and controller but slightly different views and routes in rails3

I have a model Notifications, and it basically handles the same few things. A simple contact form, an invitations form, etc. They all have the same generic items... ie Name, email, comment, blah. There might be one slightly different field but they are optional, so I'd like to treat them as one model with a differentiating field calle...

How do you seed models with HABTM relationships to other seeded models.

I'm working on my first Rails(3) App, and looking to seed a bunch of data. The issue I'm having is that I want to seed some models that have a has_and_belongs_to_many relationship with other models I've just seeded. I'm doing what seems right, but I'm not getting the results I'm expecting. I have an Asana model (simplified): class As...

Rails 3 - How to Create a Record if One Does not Exist OR Update the existing records

I'm creating a permissions table for People & Books In the permissions table I have: Permission.ID, user.id, book.id I want an admin to be able to set permissions for Users<>Books. When the user selects the permissions and clicks submit, in the Rails controller, should I be submitting to /create or /update? is there a way I can subm...

Rails 3: Getting started with user file uploads

I am new to Ruby on Rails. I'm creating an application that allows user generated content, including photo uploading. I have worked with file uploading in PHP applications, but since I'm new to Ruby and Rails, I was wondering if there is a common technique, plugin, or gem that makes managing file uploads really easy. ...

Authlogic sends the wrong activation code

Update: this question has been answered (see below). I'll leave it up in case anyone can benefit in the future. I am trying to get e-mail confirmations working on Authlogic using Rails 3. http://github.com/matthooks/authlogic-activation-tutorial Authentication is working and the activation e-mails are being generated and sent, each c...

Rails 3 - Issue with Nested Routes, It's not allow for a custom collection?

Hello, I have the following in my routes.rb: resources :projects do resources :photos, :permissions collection do get 'yourcurrentprojects', 'userprojectpermission' end end But when I do, projects/3/permissions/userprojectpermission i get a routing error: No route matches "/projects/3/permissions/userprojectpermissio...