ruby-on-rails

How to return my current time zone in RoR?

When I use return the time that the record created, it show this : 2010-01-20 15:04:40 UTC but I want the time in my specify time zone, for example, China. Is there any convenient method in RoR? ...

Ruby On Rails - redirect_to(:back)?

I have a page that lists all of the projects that has sortable headers and pagination. path: /projects?order=asc&page=3&sort=code I choose to edit one of the projects path: projects/436/edit When I click save on that page, it calls the projects controller / update method. After I update the code I want to redirect to the path that...

How I can use partitioned database with RoR?

Hi, I want to ask this question with a specific example as I am looking for a concrete answer. :) Let's say I have a set of MySQL databases sharded on user_id. For example, all users who have ids 1-10000 will go into database D1, user ids with 10001 - 20000 will go into database D2 so on.. I have a model "User" in my RoR application. ...

Is there any wrong in my object relationship?

I want which order have different order status, so I have a table called "status", in the status.rb, it likes this: class Status < ActiveRecord::Base belongs_to :order attr_accessible :name end And this is my order.rb: class Order < ActiveRecord::Base has_one :statuses end In my view, I try to call the related status like t...

RoR: Store HTTP_AUTHORIZATION in session to access .htaccess protected folder

Hi everyone, In my Ruby on Rails application, I am trying to protect part of the public folder using apache .htaccess feature to prevent access from files to non-authentified people. So I have place a .htpasswd file to protect this folder and set up apache accordingly and this work... prompting me for login/password to access the files....

Associations with :uniq => true do not always return unique results

I have a collection of geography related classes: State, Msa, County, City, etc. The classes all descend from a base Location class. The classes are related, for the most part, through a denormalized join table called geography. So I have... class Geography < ActiveRecord::Base belongs_to :state belongs_to :county belongs_to :ci...

Nested models, forms and date_select FormHelper integration

I have followed Ryan Bates tutorial on nested models. Several of my nested models have dates associated with them. In my migrations, they are actually the type "Date." Some things I have tried and problems I've run into date_select - can handle the form object prefix, but not nested models attributes select_year - doesn't work wit...

Sort by date using acts_as_solr

I have gotten sorting working from my rails application using acts_as_solr for text fields, as seen below with Title. I am having problems getting it to work for date. My model has the following class Article < ActiveRecord::Base acts_as_solr :fields[:title, {:title_s=> :string}, {:created_at_d => :date}] def title_s self.title en...

What is the best Installation Guide for installing Rails on Ubuntu 9.10?

I have a clean install of Ubuntu 9.10. I want to install Ruby 1.8, RubyGems and Rails. The install usually fails when trying to get or update RubyGems. Sorry for the lack of details, I have gotten stuck on a number of fronts. What is the best, guaranteed to work, installation guide\blog post\tutorial for installing Ruby, RubyGems and Ra...

Bizarre authlogic issue only in Production

Context: A rails app with authlogic for sigup and login Setup info: Rails 2.3.2 A controller called posts with an action 'show'. Upon login, I display the posts/index page. and when the user clicks on an item, item's details get displayed. Fairly standard stuff. All of this works fine and dandy both in Development and Production (Ap...

undefined method error, but I defined it!

Rails newbie here, trying to get a new controller working. When I try to show ann existing instance, I get an undefined method error on a helper method. Code follows. Any idea why getRecipes would be undefined?! Controller: def show id = params[:id] recipe_ids = ConcreteMenu.getRecipes(id) respond_to do |form...

What does "dispatches" files in rails src folder mean?

I just look up at rails sources and find folder named "dispatches". There is four file in it. I want to know purpose of this files. I know I use this files on my production server, but I never used to think of their purpose. I know there is something about attaching Rails app to Apache server. On my production server rails appname comman...

Can the ActionView form input methods create <input> tags with inner html?

I am generating an input like this: <%= form.radio_button("ans", ans.num.to_s) %> The generated html is: <input id="myform_ans_1" name="myform[ans]" type="radio" value="1" /> But what I am looking for is this html: <input id="myform_ans_1" name="myform[ans]" type="radio" value="1">Some Text</input> Is there an option that I can ...

Acts as Tree with Multiple Models

I've got several models that I'd like to relate together hierarchically. For simplicity's sake, let's say I've got these three: class Group < ActiveRecord::Base acts_as_tree has_many :users end class User < ActiveRecord::Base acts_as_tree belongs_to :group has_many :posts end class Post < ActiveRecord::Base acts_as_tree ...

Names of HTML form naming conventions

In Rails and CakePHP1.2, forms tend to include input elements with names like the following: <input name="comment[author]" /> Is there a formal name for the notation used in the "name" attribute? Likewise, in CakePHP1.1 I do believe that the same would have looked like this: <input name="comment/author" /> Again, is there a formal...

Authlogic openid: getting undefined method openid_identifier? error in functional test

I use Authlogic with the Authlogic-openid addon (I gem installed ruby- openid and script/plugin install git://github.com/rails/open_id_authentication.git) and get two errors. First when running functional test, I get an undefined method openid_identifier? message on a line in my new.html.erb file when running the UsersControllerTe...

How can you update a fragment cache while allowing reads from the cache during the update?

Is there a way to refresh a fragment cache in a way that allows reads from the cache while the update is taking place? I'm caching a part of an html.erb view in Rails with the cache do .. end block in erb. I'm expiring the same cache in the controller, with a call to expire_fragment(:controller => 'controllername') I'm using memcached...

Wrap a foreign API into a Ruby class

I use HTTParty to consume a foreign API, but how can I convert the response into a Ruby class or Rails model? ...

Rails: Making Settingslogic work with Cucumber

I can't seem to run Cucumber tests on views that include strings governed by Settingslogic. Scenario: Login as an existing user from homepage Given a user exists And I am on the home page can't convert nil into Hash (ActionView::TemplateError) On line #4 of app/views/home/index.html.haml 1: #greeting ...

Protecting the content of public/ in a Rails app.

I'm maintaining a Rails app that has content in the public/ folder that will now need to be protected by a login. We're considering moving those folders of files into a path outside of public/ and writing a Rails controller to serve up the content. Before we begin writing this, I was curious if anyone else has ran into this sort of pro...