ruby-on-rails

How should I use git submodules to share code between Heroku apps?

I have a few Rails 3 apps deployed to Heroku that need to share some business logic. Apparently, although Heroku's Bundler support is pretty solid, it can't yet pull from a private Github repo. So instead I'm building a couple of gems, vendoring them into each app, checking them into git, and pushing them up with the rest of my code. Th...

Is it possible to put all data access related methods in a separate class?

I like having separate classes, one class represents the entity, and that a separate DAO (database access object). Is this possible with rails and active record? ...

what's the difference between belongs_to and has_one?

Hoping someone can clarify the differences between a belongs_to and a has_one. Reading the rails guide hasn't helped me. ...

ActiveRecord query to generate output similar to sql aggregate functions

I am using Rails 3.0. I have an Orders table with customer-id and orderPrice. A separate table contains information about customers. I want to get the following information in single database query and I am not sure if this is possible. I want to get a hash of customer-names with the total amount of their order. {Customer.Name => sum(o...

string/text storage limits in a sqlite3 database

I have a note field of string type in one of my models in my sqlite3 database, but I realized that I needed to store more text than string would allow. I just ran a migration changing the type of the field from string to text. Looking at my database, it says that the type is now text(255), whereas before it was varchar(255). What doe...

Ruby on Rails attr_protected

Hi, I have the following code in my User model: attr_protected :email I'm trying to create a new user object, but I get a mass assignment protected error with the following code. user = User.new( :first_name => signup.first_name, :last_name => signup.last_name, :email => signup.email, :birthday => signup.birthday, ...

Implementing a News Feed / Activity Feed on Several Models - Recommendations?

Hello, I'm interested in learning how to implement a News Feed / Activity Feed on a web app for multiple models like Books, Authors, Comments, etc... Any recommendations from the group? Gems/Plugins, or experience personally or from others on the best/smartest way to proceed? Thanks! ...

Assistance Learning how to add this to Rails ?????

I have the following model: (goal is to create a news feed / activity feed for my app). Activity: id.int | user_id.int | item_type.string | item_id.id | created.timestamp | data.string With the intent that I can create records like: {id:1, userId:1, item_type:Photo, item_id:33, time:2008-10-15 12:00:00, data:{photoName:A trip to the...

Disqus Integration with my authentication system

Is it possible to integrate Disqus with my existing authentication solution? I am developing a app using RoR and authologic! ...

Ruby on Rails 3: Multiple routes in same namespace

My page urls are like '/about' and my city urls are like '/san-francisco'. There is no overlap. How can I get the following routes to play nice? get '/:city_slug', :to => 'cities#show', :as => 'city' get ':action', :controller => "site", :action => 'show' ...

Can Rails automatically parse datetime recieved from form text_field

Can Rails automatically parse datetime recieved from form text_field? <div class="field"> <%= f.label :created_at %><br /> <%= f.textfield :created_at %> </div> params[:product][:updated_at].yesterday Currently i get following error: undefined method `yesterday' for "2010-04-28 03:37:00 UTC":String ...

How do I use the hash :condition on a .find for a nil? method in Rails (has_one relationship)

I want to find all Contacts where the value of their :has_one relationship to :contact_status does not have a value (does that mean nil?) I created an alias_attribute :status, :status_contact Can I do something along the lines of: contacts = Contact.find(:all, :conditions => {:contact_status => nil }, :include => {:status_contact} )...

How do I pass Rails' cycle() an array of values to cycle through?

Howdy. I'd like the cycle method to take an array of values which I compile on the fly, but it seems to be interpreting it not as I'd have hoped. (In this example it's a static array, but I want it to work so that I can use arrays that are constructed variably) - some_array = ['one', 'two', 'three'] - colors.each do |color| %a{ :nam...

Form Validation Ruby on Rails

Hi All, I have done a validation check in my form to check for email,username and firstname...here is the code class User < ActiveRecord::Base validates_presence_of :email, :firstname, :username validates_format_of :email, :with => /[-!#$&'*+\/=?`{|}~.\w]+@[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])*(\.[a-zA-Z0-9...

Render OpenFlashChart image automatically within Rails

Hi, i've found this tutorial in the internet to render flash object (OpenFlashChart) as an image in PHP. http://teethgrinder.co.uk/open-flash-chart-2/save-image-js.php Unfortunately i've tried to do the very same thing but failed to do so, becauset of different implementation procedure in Rails. Does anyone here knows how to render o...

How-To Implement Cross-Browser @font-face Support in rails

I am developing a small rails app to serve fonts to other sites say a request http://url/fonts/fontname will return woff,eot or ttf font based on the browser type. This app is working fine in my localhost but not in other ip... I know the problem is something to do with Cross-Origin Resource Sharing restriction but don't know how to so...

rails curl syntax

Hi All, I can run the following command from my rails app: Hash.from_xml(%x{curl -d "admin=true" http://localhost:8888} ) rescue nil now I want to replace the "admin=true" by a variable If I have x = "admin=true" how can I then write the above command? Thanks a lot ...

archiloque-rest-client: change content-type to multipart/related when posing a file

Using http://github.com/archiloque/rest-client When posting a file using this line, the content type is set as Content-Type: multipart/form-data; boundary=301405 in the header, by default. RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb') I tried this and it still sets the header multipart/form-data. RestC...

MySql Query:: How to solve the problem of 's in data, when query is fired

I am facing such problem in which 's is present in data. while searching it does not shows data. I wanna remove SQL injection issue Code :: @search_condition = "" if !search_text.nil? search_field = search_text.split("-") @search_condition = "( address_books.organization_name like '#{search_text}%' or...

Help me converting this CURL to a Post method in Rails

I am trying to post an XML to an API which returns me an XML. I successfully did that by executing a simple CURL command curl "http://my.server.com/api/identity/emails_from_ids" --proxy dvaic.snv.fex:80 -d "<users><id>3434</id></users>" -X POST -H 'Content-Type: application/xml' -u admin:admin The above command executes successfull...