ruby-on-rails3

Ruby On Rails - Securing Downloads Area

If I upload files to my server and thus have clients/customers download these files. How may I restrict the access of the file? Such as, if I upload a file to www.domain.com/files/download.zip And if the user has correct permissions he can download the file, but what if the user knows the direct link to the file itself? Cause I can ...

Rails 3 - Building a Table, Want to Alternate colors every row

Desired Output: <ul> <li class="odd">stuff</li> <li class="even">stuff</li> <li class="odd">stuff</li> <li class="even">stuff</li> <li class="odd">stuff</li> <li class="even">stuff</li> <li class="odd">stuff</li> <li class="even">stuff</li> </ul> CSS: .odd {color:blue} .even{color:red;} In rails 3 is there a clean way to do...

Rails 3, HowTo - Pass a Setting to the Application.html.erb

Most of my views will required a wrapper of padding 10px,,, but a few will not... I was thinking of doing something like this in the view controller: respond_to do |format| format.html { render :layout => true, :padding => 'false' } And then in the application.html.erb have an IF to not add a padding class if :padding is false......

How to show an auto-incremental ID on a "create new record" form with Rails

I'm trying to create a form that will show the id that the record is going to have, prior to hitting submit on the form. For example, if I have a form to create a new project, and the previous project was id 3, I want the new project form to autopopulate with 4, so that I know that it's going to be 4 before I submit the form. Thanks for...

Rails 3- Handling a conditional Create in a Controller

Hello, I have the following in my def create controller: @photo = current_user.photos.create(params[:photo].merge(:project_id => params[:project_id]) In my app photo records are valid if they have a project_id or not.... But I need my create statement not to error and work for both cases. A. If there is a param project_id, insertit...

Rails 3 If Statement,,, IF XXX Equals At Least One (Var1, Var2, Var3)

Is the following statement possible with Rails/Ruby? If so, how :) IF XXX Equals At Least One (Var1, Var2, Var3) ...

Rails 3 - Obtaining the Lates Observer Record

Here's the current flow in my Rails App 1. User uses AJAX and creates a Photo record (stored in DB) 2. Then, the observer catches this and adds a record to the audit log ** That was all without a page refresh. The challenge I have now is that I need to have AJAX return a "news feed" item from the AuditLog created by the observer. It nee...

Rails : Can I use forms from the public/index.html file ?

I'm a newbie to Rails. Am currently using Rails 3.0 to develop my app. How to handle a form in the public/index.html file which I'm planning to use as my Home page. Usually a view's action buttons gets paired with the corresponding method of its controller. But how to handle this in case the index file in public directory. Thanks in Adv...

Open Flash Chart 2 - the ids are the same so multiples are not displaying

I can get one successful Open Flash Chart per view. I'm now trying to support multiple Open Flash Charts per view but the source code shows that the ids for both generated divs are the same: # javascript at top of view <%= javascript_include_tag "swfobject.js", :cache => true %> # view itself <%= @graph.html_safe %> # html_safe is ne...

Rails 3- Will_Paginate - Making the Pagination links more like GMAIL

Hello, I'm using the Rails 3 plugin Will_Paginate and have been using the following tutorial to learn how to customize the pagination links: http://thewebfellas.com/blog/2010/8/22/revisited-roll-your-own-pagination-links-with-will_paginate-and-rails-3/ My question is, how to make the pagination links more like GMAIL, example: 1 - 100...

Rails 3 - Understanding attr_accessible with paper_clip

Hi... Just started learning how to use paper_clip. I installed everything according the instructions and tried to upload an image (profile_pic)... I got the error that I can't mass assign profile_pic... so I added attr_accessible: :profile_pic And that stopped that error. What I'm curious about is I don't have a 'profile_pic' column i...

Keep getting nil error everywhere. ruby/rails 3

I get a NoMethodError: undefined method `get_best_compatible' for nil:NilClass in mail `from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in 'method_missing'from /usr/lib/ruby/gems/1.8/gems/mail-2.2.7/lib/mail/body.rb:143:in 'get_best_encoding' from /usr/lib/ruby/gems/1.8/gems/mail2.2.7/lib/mail/mes...

Rails 3, Paper_Clip + S3 - Howto Store for an Instance and Protect Access

I have a Rail3 app with paper_clip, with the intent to store data on S3. In the app, Users belong to an instance. I would like the data stored across all the models per instance. And would like to prevent a user for Instance A from accessing, or being able to load data from Instance B. What's the best way to handle this? thanks ...

Railscasts #228 - Sortable Table Columns

I am following Ryan Bates' railscast on Sortable Table Columns and I have successfully gotten a column to sort ascending and descending. My table is more complex than in the Railscast because I have columns from different tables. # controller @cars = Car.find(:all).order(sort_column + " " + sort_direction).includes(:manufacturers) #v...

Before save action... split input field

Hi there, I have two models and controllers: Snippets, and Tags. There is a belongs_to relationship, with tags belonging to snippets. This works well, I have a text field which creates a new tag associated with the snippet when the user submits a snippet. I want to be able to have a text field which, when submitted to a function (in t...

Migrating from Rails 2 to Rails 3 problem (nil.any?)

I've been upgrading my app from Rails 2.3.8 to Rails 3. After getting all the basic stuff done (configs, routes, and the new AR API, replacing Authlogic with Devise) and getting some mostly static pages to show up fine I get an error in the rest of my site: You have a nil object when you didn't expect it! You might have expected an ins...

Can Ruby on Rails 3.0 run on Mac OS X Leopard 10.5? (instead of Snow Leopard)

It seems that most of Rails 3, Ruby 1.9.2 can be used, but when it is sqlite3-ruby, or mysql2 gems, then it can't compile, (missing mkmf?) and the latest Xcode is needed. But the latest Xcode is for Snow Leopard only. So looks like the Macbook needs to be upgraded to Snow Leopard before Rails 3 can be used? ...

Representing a DAG (directed acyclic graph)

I need to store dependencies in a DAG. (We're mapping a new school curriculum at a very fine grained level) We're using rails 3 Considerations Wider than it is deep Very large I estimate 5-10 links per node. As the system grows this will increase. Many reads, few writes most common are lookups: dependencies of first and secon...

Rails 3 Authlogic - 'acts_as_authentic' undefined

I'm getting the following error: NameError (undefined local variable or method `acts_as_authentic' for #<Class:0x1037e6310>): app/models/user.rb:2 app/controllers/user_controller.rb:3:in `new' I'm using Rails 3.0.0, with Ruby 1.8.7. Authlogic is in my Gemfile as follows: gem 'authlogic', :git => "git://github.com/binarylogic/auth...

rails 3 - given XXX.created_at - How to output the 3 digit month + Day

Give a model.created_at I've been able to use: <%="#{time_ago_in_words(model.created_at)} ago "%> What is the helper to output something like Oct 8 Sep 23 Aug 31 Jul 11 Bonus points, if it outputs like above, but for any records that were created today (not 24hrs ago but today). it shows the time, example: 4:31pm 1:20pm 9:31am...