ruby-on-rails

(Rails) Managing a tree without javascript?

Hi All, I'm looking for some non-javascript techniques by which to reload a page of tree items (basically divs within divs) while remembering their "show/hide" status. So far the only thing I can think of is to pass every entity's ID as part of a parameter list and have Rails then insert a "class-display" in the class list (or, of cours...

Complex Join Queries in Rails

Hi, I have 3 tables - venues, users, and updates (which have a integer for rating) - and I want to write a query that will return a list of all my venues as well as their average ratings using only the most recent update for each person, venue pair. For example, if user 1 rates venue A once at 9 am with a 4, and then rates it again at 5...

How can I show the git branch of a rails app within that app?

I've got a couple of different branches of a rails app running in a development environment on the same server (on separate databases, obv), and I'd like to make it very clear what branch is being shown when I hit the app through the web. Any ideas, short of running git-branch or git-symbolic-ref HEAD in backticks and parsing the output...

Lightbox for rails?

Does anyone know of a good lightbox plugin for rails? I found redbox but it seems to be out of development. Thanks! -Elliot ...

Redirect_to with multiple controllers with shared tables - in rails

Hey guys, I'm pretty new to rails, so I apologize if this question has an obvious answer. I have multiple controllers with records stored based on relations for example, /books/1/titles/4 meaning the the title with ID 4, is only related to book with ID 1. in an action such as destroy, how can I use redirect_to to go to /books/1/titl...

Controller related to multiple controllers in rails

This is a tough one I think. I have a comments controller, that I'd like to use for all of my other controllers: such as books, titles, etc. The problem is, the create action in comments is: def create @book = Book.find(params[:book_id]) @comment = @book.comments.create!(params[:comment]) respond_to do |format| format.html...

Search for all blog posts created on a given day

My blog posts have a created_at datetime attribute. How would I use Blog.find to retrieve all blog posts created on a given day (say 1/1/2009) ignoring the time on that day they were created? ...

Rails: Showing 10 or 20 or 50 results per page with will_paginate how to?

Hi community, me again... I need show 10 or 20 or 50 results number of results per page with a select options in my list of posts using will_paginate plugin Can you help me please? Thanks! ...

Any suggestions for a ruby solution for populating a sqlite database from a mysql source

I have a Rails application that uses MySQL. The application needs to populate sqlite databases to be distributed to client applications from the master mysql database. The schema for the sqlite database will be very similar to the mysql database, but not identical. The sqlite databases will be populated with a subset of the schema and ...

Mysql results sorted by list which is unique for each user

Ive got a table of thousands of products and 50 or so authenticated users. These users all show the products on their own web sites and they all require the ability to have them ordered differently. Im guesing i need some kind of seperate table for the orders which contains the product_id, user_id and order column? How do i do this t...

Controlling Marquee Speed using Javascript

We are trying to develop an eShop. One of the functionality demands us to show a marquee with any recent buying / selling / updating activity that happens on the site. Currently we do get the marquee, however every time the page is refreshed the scrolling speed goes on increasing automatically. We are trying to discover a way so that it ...

A Very n00bish Ruby on Rails doubt.

I am kinda new to Rails 2.3.3. This question is kinda simple, I have been tryin to overcome this issue but haven`t been able to. Database and Model Schema User (id,name,email) posts (id,subject,message,user_id) Can you please temme how to display the name of the user who has created a particular post #posts controller #index action...

Is it wrong to not implement all REST actions in Rails controller?

Let's say I have a SessionsController, which controls user login and logout, but the only actions I really need are new (for displaying login form), create (for authentication and login) and destroy for logging out the user. Is there any problem if I just have these three actions in my controller, or do I have to implement them all to m...

Problem with setter override on ActiveRecord

This is not exactly a question, it's rather a report on how I solved an issue with write_attribute when the attribute is an object, on Rails' Active Record. I hope this can be useful to others facing the same problem. Let me explain with an example. Suppose you have two classes, Book and Author: class Book < ActiveRecord::Base belong...

How can you render a template within a layout using Liquid template language?

I'm trying to render a liquid template within a liquid layout (Liquid Template lang, not CSS liquid layout stuff). I can't seem to get the layout part to render. Currently using: assigns = {'page_name' => 'test'} @layout = Liquid::Template.parse(File.new(@theme.layout.path).read) @template = Liquid::Template.parse(File.new(self.templa...

Adding a "tools mode" to rails app

Let's say I have a rails app with content that's read-only to the public, but I'd like to build tools to edit that content (or use scaffolding). I don't want to expose create/update/delete actions publicly (even if password-protected), but I'd like to have a server with this functionality inside a local network that interacts with the pr...

render_to_string stripping markup

I am using render_to_string within a JSON 'render' response. The render_to_string method seems to be striping my HTML, what am I doing wrong here? Here's a sample: render :json => {:html => render_to_string(:partial => 'view', :locals => { data => @data} )} The response is coming through without any markup on it. ...

Best Practices for receiving email in rails

Hey Everyone, I've been trying to figure out the best way to handle incoming email in a rails applications. I realize "best practices" is quite subjective, so I'll start by stating that my primary concerns are scalability and efficiency. This is an issue primarily because my use will involve handling potentially large attachments. Se...

Rails Polymorphic relationship and link_to

Here's my Schema class Menu < ActiveRecord::Base belongs_to :menuable, :polymorphic => true end class Page < ActiveRecord::Base has_one :menu, :as => :menuable end class Links < ActiveRecord::Base has_one :menu, :as => :menuable end I want to link to a polymorphic class in the Menu view using link_to, e.g. <%= link_to menu.na...

Is it possible to retrieve the original order of POSTed values in a Rails controller?

A Rails controller receives the POST values in a hash, which has no natural order, but for my application I need it, because the user can change the order of the form fields via Javascript. (via Sortable from jQuery) Is there any other way to retrieve the posted values in their original ordering? ...