ruby-on-rails

Is strftime (hour) showing wrong time?

I'm using this line to get the beginning time of the first day of the month. t = Time.now.to_date.beginning_of_month.beginning_of_day When i display this using t.strftime("%A %b %e @ %l:%m %p") it shows: Monday Feb 1 @ 12:02 AM The hour is always 12 (instead of 00), and more wierd the minute changes to match the month in inte...

Rails session cookie not getting set

I have a rails app that is a CMS that uses dynamic subdomains for each site. For some reason when I deployed to production the session cookie is not getting set. I'm thinking this is leading to the "Invalid Authenticity Token" errors that are being thrown everywhere. I have my production.rb setup so that I can share sessions across ...

Rails: Mark a class as NOT reloadable

I've got a few classes in lib/ which are not reloadable (due to their internal structure, its a jruby application). How can I tell rails to not reload these after each and every request? Thanks! ...

Conditional Validation with Paperclip difficult

Hi, I have an "item", which goes through a multi-page creation process. Images are uploaded at step five, and I keep track of the steps by using the attribute "complete". When validating whether an image is attached with paperclip, I get problems using the code below: validates_attachment_presence :pic1, :if => Proc.new { |u| u.comple...

Controller doesn't equal to model name in Rails

Hello, I've model called BlogPost and controller called BlogPostsController that has all basic CRUD methods for BlogPost. I'm trying to understand how I can route users to have URL like /blog/post-name instead of /blog_posts/post-name and "disable" in general URL /blog_posts. Should I rename my controller or should I change routes (and...

Why do I have to run migration twice for values to appear in DB?

Inexplicably, when I run the following migration code using rake, the column, but not the values, appear in the MySQL DB table: class AddTypeToItems < ActiveRecord::Migration def self.up add_column :items, 'type', :string, :limit => 100, :null => false Item.find_by_name('YUMMY_JUICE').update_attribute(:type, 'Juice') Item...

Rails: DRY in views

Hy, I have a layout in the views/layout that has 2 cols and then in every view i have content_for :main_col and content_for :side_col. The problem is that i have more than 5 views with the same content in the content_for :side_col You have a better idea on how to do this?thanks ...

Why would Ruby fail equality on 2 floats that appear the same?

Hi there, I have a calculation that generates what appears to be the Float 22.23, and a literal 22.23 like so: some_object.total => 22.23 some_object.total.class => Float 22.23 => 22.23 22.23.class => Float But for some reason, the following is false: some_object.total == 22.23 ? true : false Wacky, right? Is there some kind of p...

Rails: using set_table_name to join across different databases on the same mysql server

For legacy reasons, my model's tables are stored in two different databases on the same MySQL server. At first I just used establish_connection to specify the second database on the models that used it. However, when I established a has_many :through connection between two models in different databases, it blew up because MySQL cannot ...

Passing custom info to mongrel_rails start

One thing I really don't understand is how I can pass custom start-up options to a mongrel instance. I see that a common approach is the use environment variables, but in my environment this is not going to work because my rails application serves many different clients. Much code is shared between clients, but there are also many diffe...

Validate number of nested attributes

Hello, I have a model with nested attributes : class Foo < ActiveRecord::Base has_many :bar accepts_nested_attributes_for :bar end It works fine. However I'd want to be sure that for every Foo, I have at least two Bar. I can't access the bar_attributes in my validations so it seems I can't validate it. Is there any clean wa...

Building Admin Areas in Rails - General Questions

What is the typical format/structure for creating an administrative area in a Rails application? Specifically I am stumped in the vicinity of these topics: How do you deal with situations where a model's resources are available to both the public and the Admin? i.e. A User model where anyone can create users, login, etc but only the ...

MySQL use certain columns, based on other columns

I have this query: SELECT COUNT(articles.id) AS count FROM articles, xml_documents, streams WHERE articles.xml_document_id = xml_documents.id AND xml_documents.stream_id = streams.id AND articles.published_at BETWEEN '2010-01-01' AND '2010-04-01' AND streams.brand_id = 7 Which just uses the default equajoin by specifying three tabl...

Ruby on Rails Foreigner plugin not working for SQL Server

Well, now that I've finally got my stupid ODBC stuff configured, I took a schema.rb file that I dumped from a Postgres database and did a db:schema:load on it in a Rails project configured for SQL Server. Well, it sets up all the schema in the SQL Server database except for a minor detail: No foreign keys are created. The rake command...

Solution for social network + marketplace with multiple sellers?

I want to build a social network, with some of the users being able to put up some stuff up for sale. So basically, a social network + multiple sellers e-commerce. What is the best technology solution for that? I was thinking of going Rails route, using CommunityEngine and ActiveMerchant. Another option is going PHP and using something...

two sortable lists need to get serialize parameters using jquery-ui

hi guys! can you help me with these codes: http://pastie.org/908345, its two sortable lists and I need to get the serialize parameter of those lists to be passed when I click the submit button but I always get "(an empty string)" on "console.log". I'm using jquery-ui for this functionality. thanks! ...

How do I display two different objects in a search?

github url I am using a simple search that displays search results: @adds = Add.search(params[:search]) In addition to the search results I'm trying to utilize a method, nearbys(), which displays objects that are close in proximity to the search result. The following method displays objects which are close to 2, but it does not displ...

Javascript html grab from external iframe + calling a controller action with data

Preface: I consider myself "slightly effective" in ruby on rails, and a complete novice in javascript. Also, yes, I have installed jQuery and associated plugins instead of the default Prototype library. I am in a situation where I am pulling in a table from off-site in an iframe (which is taking care of all internal JS for me) such that...

Dynamic URL -> Controller mapping for routes in Rails

I would like to be able to map URLs to Controllers dynamically based on information in my database. I'm looking to do something functionally equivalent to this (assuming a View model): map.route '/:view_name', :controller => lambda { View.find_by_name(params[:view_name]).controller } Others have suggested dynamically rebuilding t...

Imagemagick - File Naming

I am using the convert command to convert a pdf to multiple pngs, I need the naming conventions to be slide-##.png at the moment they come out like slide-1.png but because there is 20+ slides when I loop through them to add them into the model the order comes up wrong, so it looks like slide-1.png slide-10.png slide-11.png and so on, how...