ruby-on-rails

Is unobtrusive RJS files in Rails 3 considered a good idea?

I'm working on implementing javascript functionality in my rails 3 app. Now that rjs is supposedly unobtrusive (I honestly don't know a lot about rjs), is it still "evil"? It seems to me the downside may be a lack of testability, but partial page updates via rjs seem to be easier than jumping through the rails hurdles to make ajax requ...

How to create a project template for Ruby on Rails projects?

When I build Rails applications I find myself doing the same things over and over again. This includes adding the same gems/plugins, configuration info and custom initializers, rake tasks etc... etc.... This can't be a good thing. So, is there a way to package all this repetitive code into some sort of project template ... so that I c...

Authlogic_OpenID - "uninitialized constant Rack::OpenID"

So I followed the railscast tutorial (http://railscasts.com/episodes/170-openid-with-authlogic) and used the old version of the plugin from Ryan's git file. I can now successfuly create/register a user using OpenID (Google), but I cannot log in with this user. When I submit the OpenID that has been registered, I get "uninitialized consta...

Rearranging parts of the URL result from link_to in Rails

This is how I'm doing it now: link_to "Profile", :controller => "profiles", :action => "asked", :id => @profile # => <a href="/profiles/asked/1">Profile</a> Does it make more sense for the URL to be <a href="/profiles/1/asked">Profile</a>? Profile 1 asked some number of questions, so it makes more sense to me for the URL to look like...

How to open URLs in rails?

I'm trying to read in the html of a certain website. Trying @something = open("http://www.google.com/") fails with the following error: Errno::ENOENT in testController#show No such file or directory - http://www.google.com/ Going to http://www.google.com/, I obviously see the site. What am I doing wrong? Thanks! ...

Best Practice for Uploading Many (2000+) Images to A Server

Hello, I have a general question about this. When you have a gallery, sometimes people need to upload 1000's of images at once. Most likely, it would be done through a .zip file. What is the best way to go about uploading this sort of thing to a server. Many times, server have timeouts etc. that need to be accounted for. I am wonderi...

How can I keep an url request from being saved in the log in ruby on rails?

Possible Duplicate: How can I disable logging in Ruby on Rails on a per-action basis? I use an ajax "ping" for keeping track of the online users, and for alerting them about notifications if any. However, this constant request are being logged in my production.log file, and that's not funny, since I want to keep track of the a...

Where to put a piece of code in Ruby on Rails?

I have a post controller that has many comments. The post model has a field called has_comments which is a boolean (so I can quickly select from the database only posts that have comments). To create a new comment for a post, I use the create action of my comments controller. After I create the comment I need to update my post's has_com...

How can I get the error messages ,when there is a error happened in $.getJSON

In "get_data" action ,there are some code like this: def get_data if params[:p]=='1' raise "error 1" elsif params[:p]=='2' raise 'error 2' else return data end end in view: <script> $.getJSON('/controller/get_data',function(){...}) </script> so,when some error has raised,how can i get it! Tks! ...

rails question find no result

Hey.Guys! Now .I have a question ,i want someone to help me to solve it ,the log of the problem like the under text >> Department.find(EmeReference.find(:all,:select =>:ref_config_id,:conditions=>"emergency_id = 1")) ActiveRecord::RecordNotFound: Couldn't find Department with ID=0 from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib...

#validate does not seem to work correctly with :on => :create/:update

Greetings, I have a custom validation in my exemplary Movie model: class Movie < ActiveRecord::Base validate :it, :on => :create private def it self.errors.add 'foo', 'bar' end end This works on movie creation but also on updating an existing movie. :on => :update will also work for both. Might that be a bug or am I mis...

Ruby on Rails - observe_field help

Trying to put in field "pagar" the calculated value of "precio" * 15% but I don't know why it is not working :S <% form_for @libro, :html => { :multipart => true } do |f| %> <%= f.label "Precio (si es venta):" %> <%= f.text_field :precio %> <%= observe_field :libro_precio, :frequency => 0.25, :update => :libro_pagar, :with ...

How to implement a Counter Cache in Rails?

I have a posts controller and a comments controller. Post has many comments, and comments belong to Post. The associate is set up with the counter_cache option turned on as such: #Inside post.rb has_many :comments #Inside comment.rb belongs_to :post, :counter_cache => true I have a comments_count column in my posts table that is defa...

how to check string is valid date or not in rails

Hi All, i have a string say "31-02-2010" now i want to check that wheather this date is valid date or not . what is the best way to do it? so i need a method which i operate on string which returns true if date is valid and false if it's invalid. ...

Thinking sphinx not rendering results in order of 'relevance'

Thinking sphinx documentation says that it automatically sorts the results based on relevance. What is its relevance metric ? How can we define our own relevance metric for the system ? Example : I have a db in which one entry is Windows XP & it contains a reference to Microsoft. I also have an entry for Microsoft itself. So when I quer...

Ruby fixtures error with password column

I am trying to load a fixture for my tests which has a password column (binary datatype). The tool i am using uses EzCrypto gem for encrypting and decrypting passwords before they are stored/retrieved. Now if my column is binary i thought rails would automatically store the password as encrypted - but all i get is: 1) Error: test_is_wor...

Create select based on routing, how?

I am trying to implement navigation like in Tree Based Navigation but based on URLs defined in routes.rb (named routes, resources, ...). Is it possible to retreive a collection of all routes defined in routes.rb? So I can use it in a select like this: <%= f.collection_select :url, Route.all, :url, :name %> Tnx! ...

Rails gives wrong headers after upgrade 2.3.5 -> 2.3.8

I just upgraded from rails 2.3.5 to rails 2.3.8, but now my redirects are not working properly. I get the following as the response HTTP Headers: HTTP/1.1 302 Moved Temporarily Date: Wed, 02 Jun 2010 09:40:39 GMT Content-Length: 93 Content-Type: text/html whereas I got previous: HTTP/1.1 302 Moved Temporarily Connection: close Date:...

How to model has_many with polymorphism?

I've run into a situation that I am not quite sure how to model. EDIT: The code below now represent a working solution. I am still interested in nicer looking solutions, though. Suppose I have a User class, and a user has many services. However, these services are quite different, for example a MailService and a BackupService, so singl...

How to use Many to Many in Rails?

Hello! In my project, I have users and quests. One User can join multiple quests and one quest can have multiple users. So I created a table called questing, containing the user_id and the quest_id. In my user.rb I did following: require 'digest/sha1' class User < ActiveRecord::Base has_many :questings has_many :quests ,:through =>...