ruby-on-rails

(rails) how to validate whether an uploaded .txt file is not, say, an image file?

I have a upload text file field, and with it I plan to save the file somewhere and then store the location of the file in a database. However, I want to make sure the file they uploaded is a .txt file, and not, say, an image file. I imagine this happens in the validation step. How does one validate such a thing? Also, how do you get the ...

Question related to mysql gem new method authentication

I normally code on windows and using MYSQL4.1. And mysql gem version is 2.8.1. In my setup when I use mysql gem to access the MYSQL server, I give the root username and password of the sql server. And in rails db config file, I give user name as 'root' and its password and host as 'localhost'. My rails server and Mysql server are running...

Emacs session / projects / window management

Hello, I am working with Ruby on Rails projects most of the time so I need a way to save projects and the state of the buffers/windows I am working on, mostly because I often find myself switching to a different project for a few minutes and then going back to the project I was working on. Desktop.el seems to be very close except for th...

Ruby on Rails is/are pluralisation

Is there a helper to avoid this sort of code? = @leads.length == 1 ? 'is' : 'are' I know about pluralize but it doesn't help in this case. I know that writing a helper would be trivial, I want to know if there's something in the Rails API that I have overlooked. Thanks, -Tim ...

how to show video image in list ROR

i have uploaded video but when i see them in list ,, i want an image of a video ,, please help for showin image of video in list ...

How to use common named_scope for all ActiveRecord models

Hi how to build a named_scope which will be common for all models. ...

Rails Filter records of child model based upon the parent model attribute

Following are the 1-to-M models: class FotoGossip < ActiveRecord::Base has_many :uploads attr_accessible :published_at, ... end class Upload < ActiveRecord::Base belongs_to :foto_gossip end Now I want the Uploads.all with the condition :published_at NOT NULL of the corresponding upload's parent model? ...

Unpacked Ruby gems and environment.rb

Do I need to config.gem a gem that's already been unpacked? ...

How do you save an uploaded file to a directory and not a DB?

If someone uploads an image via a form, how do you save the image in public/images and not in a model? And I do NOT want to use plugins. ...

Rails 101 | validates_currency ??

Hi guys, I've searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or 1000 or $12.12 and in an ideal world even 1 million) In the database I want to keep the value as a integer. What is the best way t...

Acts_as_tree - one-to-Many: Show Records associated with children on parent page

Hi, I have a relatively simple one-to-many relationship and use acts_as_tree to get it organized in the view. It kinda looks like this: Root |_Product 1 |_Product 2 |_Category 1.1 |_Product 3 |_Product 4 |_Category 1.1.1 |_Product 5 The way I set it up is that I list products in the 'sh...

How to use parameterize in Rails?

I want to convert the title of a page to a friendly URL and store it in the database as a permalink. My problem is I can't use the parameterize method. It's not working. Other inflections are working like upcase or downcase but parameterize is not working. Is there a special case for parameterize? This is my code: Controller: def cre...

How can you load the Rails environment from CloudCrowd actions?

I'm writing an "action" for CloudCrowd which needs access to the Rails environment (for some ActiveRecord stuff) but the standard means of loading the environment is resulting in fishy errors. I tried each of the following at the top of my action .rb file: require(File.join(File.dirname(__FILE__), '../..', 'boot')) and require Fil...

Can't find gems in irb: "NameError: uninitialized constant Gem from (irb)"

When I run a Rails app it finds all of my installed gems correctly. This is the first time I tried to call some gems from inside irb and it couldn't find them. blocke:~$ irb irb(main):001:0> require 'rubygems' => true irb(main):002:0> require 'rails' LoadError: no such file to load -- rails from /usr/local/lib/site_ruby/1.8/rubygems/c...

What gems should I use to have a Ruby app talk to an LDAP server?

My overall goal is to let users of my Rails app authenticate against our organization's ActiveDirectory server over LDAP. (Did I say that right?) I'd like to try the Ruby ActiveLDAP gem. The docs say it depends on either... RubyLDAP or... ruby-net-ldap Does it matter which one I use? Am I heading in the right general direction by ...

problem with link_to_remote in Rails 2.1

I am facing this strange problem with the following section of code <% if (@more == -1) %> <%= link_to_remote "More Posts", :html => {:id => 'more-link', :onClick => 'return false;'}%> <% else %> <%= link_to_remote "More Posts", :url => {:action => 'view' ,:id => @more.to_i + 1} , :html => {:id => 'more-link'} %> <% end %> Now whe...

How do I install will_paginate in ruby?

I'm trying to install will paginate. I installed the gem, as detailed on the github page. The gem installed OK, but when I tried a line like @user = User.paginate I just got an error message about the paginate method not existing. So, I uninstalled the gem and tried using the plugin method: script/plugin install svn://errtheblog.co...

How do you get the rows and the columns in the result of a query with ActiveRecord?

Is there a way with ActiveRecord to execute a custom SQL query and have it return an array of arrays where the first row is the column names and each following row is the row data? I want to execute something like: connection.select_rows_with_headers "SELECT id, concat(first_name, ' ', last_name) as name, email FROM users" And have i...

Using selenium-client to click a button that is part of a form

Hey, this should be pretty simple, but it's causing me a lot of grief! I have lots of buttons like this: <form class="general" method="post" action="/password"> <div style="margin: 0pt; padding: 0pt; display: inline;"> <input type="hidden" value="Yg4EweyWwXO8RAF9nd3RZKNmQw8Yk+f2vefLQ/IENyg=" name="authenticity_token"/> </div> ...

Help with rails restful authentication

I just installed the restful authentication using this plugin and when I go to localhost:3000/login i get this error NameError in SessionController#new uninitialized constant SessionController Any ideas? please help. ...