ruby-on-rails

Force current_user path

Currently users can access their "profile" through many paths. localhost:3000/users/current_user localhost:3000/users/current localhost:3000/users/id# How can I make it that they can only get to their "profile" through localhost:3000/users/current_user ...

github url style

Hi all, I wanted to have users within my website to have their own URL like http://mysite.com/username (similar to GitHub, e.g. my account is http:// github. com/sr3d). This would help with SEO since every profile is under the same domain, as apposed to the sub-domain approach. My site is running on Rails and Nginx/Passenger. Current...

Which is a better way to detect a client's user-agent?

I am interested if which would be the best place to detect the client's user-agent, client-side (javascript) or server-side? I brought up the question due to the fact that some IE8 users are getting a message saying they're using IE6. ...

Is there any way for the controler to get values from a form in your view before it is saved?

I assume the values must be passed back to the controller for use, but everything I have tried seems to only get values that have already saved in the db. ...

Unobtrusive Toggling in a Loop

Hi everyone, I'm using Unobtrusive Toggling in a view that contains many records (Orders). I've got it working on individual divs, but I now want it to work so each Order can be expanded/contracted individually within the loop using its own toggle link (the link is also looped). When my expandable div is called x, the problem is every ...

Why rails platform developers are changing the syntax?

Hello I am new to Rails. I am learning rails 2.3.5 and checked Rails 3. I found some features added in Rails 3. That's perfectly fine. But I found something different. in 2.3.5 we use ruby script/server to start the server and in Rails 3 we use rails server and there are some other changes like this. What's the improvement by ...

Rails Random Active Record with Pagination

I need to find all records for a particular resource and display them in a random order, but with consistent pagination (you won't see the same record twice if you start paging). The display order should be randomized each time a user visits a page. I am using will_paginate. Any advice? ...

Thinking Sphinx and lack of updated records

We are running thinking sphinx on a utility instance in our server cluster. It is rerunning the index every minute. But, if you make a change to a record, it disappears from search results until the index is updated (up to 1 minute). Is Thinking Sphinx only returning rows that have updated_at times that less than their last index? If...

Switching/Linking to another external stylesheet in a .js file using Ruby on Rails

Im learning JQuery from a Sitepoint Book but Im trying to apply all the lessons to a Rails App. In one lesson, we are taught how to switch to a different stylesheet if the browser window is resized beyond a certain point. Here's the javascript code: if ($('body').width() > 900) { $('<link rel="stylesheet" href="wide.css" type="text/c...

DOM Elements with same id and jQuery

Hi I have multiple elements with the same structure in my application. Second div element's id varies as per the comment id in the db which is unique. There are elements with the id 'vote_up' and 'vote_down'. This gets repeated for each comment.What happens is that, as I mentioned, there are multiple comments. I want to perform an Ajax r...

BIRT Viewer with Rails App

Has anyone tried using BIRT for reporting on a Rails app.. I am working on a pretty big app on ROR. I was trying to get BIRT to work happily with the app. Since the BIRT Report Designer cannot be used with Rails, I decided to use BIRT Viewer alone and give the links to the reports on the page and have BIRT Viewer running on Tomcat on the...

Compare a DateTime to the current date

Hi I am trying to use a condition on events when the start_at DateTime is equal to or greater than Today's date. I want to list upcoming events, but clearly they are not upcoming if they have already passed. I have: @appointments = Event.find(:all, :conditions => ['move_id = ? AND start_at = ?', @move.id, Date.today]) I think I may...

Get Rails to save a record to the database in a non-UTC time

Is there a way to get Rails to save records to the database without it automagically converting the timestamp into UTC before saving? The problem is that I have a few models that pull data from a legacy database that saves everything in Mountain Time and occasionally I have to have my Rails app write to that database. The problem is th...

in HAML, how to write comments in :javascript region so that comments not shown to the public?

in HAML, we can write comments using -# some comment and it won't become HTML and made public but if it is inside :javascript -# comments like this line will break the javascript interpreter as it becomes javascript code // so we are forced to use comment like this and is publicly viewable is there a way to make it non-public?...

Using accepts_nested_attributes_for with a belongs_to association, and using find_or_create_by_attr behaviour

I am building a Rails application which allows a user to create an object that refers to multiple other models, creating them if they do not exist, and just associating to ones that already exist: # app/models/upload.rb class Upload < AR:B belongs_to :user belongs_to :observed_property belongs_to :sensor accepts_nested_attribut...

Know of a Django / Rails enterprise level support services?

I am starting a new project for a client from the academic sector. We are trying to choose the right technology for the project and I am interested in hiring Django or Rails developers to work on it (as there will be some custom module development involved). The client wants to be able to sign up with a reliable service package after lau...

case insensitive search in rails - an example from Beginning Rails

Hi, Could some on help me to turn the following search into case - insensitive? Here is the piece of code for earching "title" field in event module: # Add each field to the conditions array searchable_fields.each_pair do |field, value| conditions << "#{field} LIKE ?" values << "%#{value}%" end Here is the data I have entered: ...

Within a category, "Seach all posts" checkbox, how to?

Hi, I have set up my routes so I can search all posts with: /posts/search/foobar or search inside a category /posts/category/1/search/foobar It works pretty well, when someone is browsing an specific category it does search just posts that belongs to that category. When inside a category, I want to place a checkbox to "Search all...

Rails association query

I am having trouble accessing the correct information in my rails model (which I believe to be correct) The schema for my tables are create_table :schools do |t| t.string :name t.timestamps end create_table :variables do |t| t.string :name t.string :category t.timestamps end create_table :data do |t| t.string...

Ruby/Rails question about locating help/definitions w/in the system

This is probably super basic but, well, I can't find it... What's the best way to explore Rails from within the installation itself. Let me explain. I'm looking at some Migration code and curious what a symbol means. How/where do I look that up? In this case, specifically, i'm curious about :force => true and what it's doing but the mor...