ruby-on-rails

Ruby on Rails - prepopulate new record

I have a form for a nested resource (Client :has_many Workouts) that I want to pre-populate based on some user input (I use this input to set up some other default parameters for the new action). <% form_tag new_client_workout_path(@workout_user) do%> <%= date_select nil, :date %> <%= submit_tag 'Enter New Workout' %><br/> <% e...

Ruby on Rails: named Scope OR is getting translated into AND when it becomes SQL

{ :conditions => ["#{"(visibility = #{Shared::PUBLIC}) || " if include_non_employee_public} (visibility IN (#{employee_privacy}) AND user_id IN (#{users}))"] } there is my condition for my named scope. now i've tried both || and OR in the named scope, but the console always shows AND. any ideas? ...

Machinist for Non-ActiveRecord Models

Is it possible to use Machinist to create blueprints for non-activerecord models? Seems to generate an error no matter what I try! If this is impossible with Machinist, is there another fixture generating gem that can do it? I've also read that Factory Girl has issues with this. ...

Google Apps and Open ID Authentication in Rails - Security

I'm moving an app to use only Google Federated Login (OpenID) for an application (we use google apps for everything and feel it would be easier to combine user management there). While I can successfully login and create users, my thoughts are now on security... When a user logs in I only have a "Log In" button - nothing else. The sit...

converting has_many and :belongs_to with has_many :through

I have a current association where: Group :has_many Employees and Employee :belongs_to Group but now I want an Employee to be associated to many Groups as well. For this purpose I am thinking of making: groupizations group_id:integer employee_id:integer created_at:datetime This will change Employee and Group models: class Groupiza...

ruby on rails way to destroy extra session variables in a model?

I have additional variables I add to an authlogic users session like: session[:current_profile] = extra_id I currently destroy these on logout in a controller like: session[:current_profile] = nil I'd like to clean this up and destroy them in the session model in the after_destroy method like: def after_destroy session[:current...

Restrict access to some model items in Rails 3

I have Post model with published? field and some authorization system which defines admin? method inside ApplicationController. I want to restrict access to unpublished posts and show them only to administrator. I tried to define a scope accessible to return only published posts to users, but all posts for administrator. scope :publis...

Rails user queue system?

I would like to create a Rails app that would allow users to control the serial port of the host server. To keep some order to the serial commands, I would like to have some sort of queue system that would only allow one user at a time to issue commands, with a time limit. When their time expires, the next user in the queue is given cont...

How can I merge :conditions for my SQL query

Let's presume that I have two different conditions :conditions => ["base == ?", self.search_text] and :conditions => ["status = ?", "#{self.status}"] Is there any way to merge these conditions into one query? ...

Ruby on Rails: Dynamically choose a class to search from.

How do i have a variable such that sometime I can do Foo.find(id) or sometimes Bar.find(id) there not constants so .constantize won't work =\ ...

Troubleshoot creating a new record in Rails using Ajax

I am implementing a "favorites" feature into a community blog application, and would like to use Ajax. When users like a front page post, there is a "+" symbol they can click to add that post to their collection of favorites. The feature works great without Ajax functionality. But now I'm adding the Ajax. In the view: <span id="favo...

Rails3: Serve a file statically that is not in "public/"

How do I serve a file statically with the correct content-type headers if it is not (for good reason) in the "public/" directory? ...

Ruby on Rails: is there a way to retrieve a javascript var from render :udate do |page| ?

I can set javascript variables.. but can I retrieve them? if so. how? ...

Liquid view_paths error

I'm trying to deploy my RoR app. It seems to be working fine on my development machine when RAILS_ENV is set to development. However, when I put it on the production server and set it into production mode I get the following error after navigating to the start page: => Booting Mongrel => Rails 2.3.8 application starting on http://0.0....

Rails won't serve static files in production

Hello I recently updated my app from 2.3.8 to 3.0.rc, but after a while in development environment I tried the production environment. But now it won't serve static files. I use standard development and production environment settings, and have no unique gems for either environments. Everything works like a charm in development, but it ...

why use include module when class_eval by itself would suffice

In the following code include module is used. The way I see it if include module is removed then also an instance method would be created. Then why user include module ? http://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb#L1416 include Module.new { class_eval <<-RUBY, __FILE__, __LINE__ ...

no such file to load -- thinking-sphinx

When running script commands like script/console I get the error message: no such file to load -- thinking-sphinx In my evironment.rb file I have: config.gem 'thinking-sphinx', :version => '1.3.18', :require_as => 'thinking_sphinx' In my rake file: require 'thinking_sphinx/tasks' I have following versions: gem 1.3.7 ruby 1.8.7 ...

Terminal says delayed_job starting, but not doing anything

I have an app that works perfectly on my local machine and am deploying it now. I have the VPS all set up and it pretty much works, as well. My problem comes from not being able to start delayed_job. I do the "ruby script/delayed_job start RAILS_ENV=production" while SSHd to the app and it returns "delayed_job: process with pid 11547 sta...

youtube video upload with uploadify and paperclip custom processor ruby on rails ???

hi all I have a file uploader that currently uploads images / pdf with a nice progress bar using uploadify and saves to S3 using paperclip. I want to upload videos the same way but instead of to s3, i want to save to youtube. Is there a processor or something that i can use to save to youtube ? Would i be able to see the progress via...

Making a simple ajax post in jQuery and Ruby on Rails

I am trying to make a Ruby on Rails post via AJAX, and can't figure it out. So close! HTML: = link_to image_tag(current_user.votes.any? {|v| v.votable_id == post.id && v.value > 0} ? 'vote-up-selected.jpg' : 'vote-up.jpg'), vote_up_post_path(post) CONTROLLER: def vote_up get_vote @vote.value += 1 unless @vote.value == 1 @vote....