ruby-on-rails

Managing mailing list archives in Rails?

I was wondering if there was a gem for managing and archiving mails on a mailing list. Somewhat like railsarchive but with some additional features like categories likes and trending etc. If not, can somebody help me with the basic architecture? TIA ...

Arabic Stemmer using ruby

is there an efficient Arabic stemmer using ruby? Thanks a lot ...

How to consume Rest API with complex objects using Httparty and Ruby

I am trying to implement call this API method in Ruby https://zferral.com/api-docs/affiliate#aff-create-usage-example which expects this object: { "affiliate" : { "email" : "[email protected]", "send_user_email" : "1" }} Using a Httparty class, I call this: result = self.class.post("/api/#{@apikey}/affiliate/create....

multi submit form

How will i have a form having more than one submit buttons..? And how will i know in the controller's action that which submit button is clicked..? ...

Rails ActiveRecord Model design

I have 3 models. Users, Groups, Employees all of the three have many to many. user has many groups groups have many users groups have many employees employees have many groups So I've created two new models: Departments (handles many to many between Users and Groups) Employments (handles many to many between Groups and Employees)...

Access the "request" variable on Rails controller tests

I have the following code require 'test_helper' class ApplicationControllerTest < ActionController::TestCase test "should display the page in german" do get :index assert_response :success # ... request.env["HTTP_REFERER"] = :index # ... end end If I run this rails functional test with $ rake test:functionals...

ERB in command line with render :partial method in html.erb

I want to render an HTML-EMail and send it to our customers using some ERB Templates. The basic code I am using: ERB.new("newsletter.html.erb").result(binding) doesn't allow me to add partials to the html.erb-File. I would love to move the header and footer to a partial and use the render :partial-Method in that call. Is this possib...

Rails: Serialize value as comma-seperated and not as YAML

Hi there, I'm looking for a way to store a serialized value of eg. IDs in a column. In before claims that this is not an optimal design: the column is used for IDs of associated records, but will only be used when displaying the record - so no queries are made with selection on the column and no joins will be made on this column either....

Paperclip plugin issue

I have a rail application, i have the feature to upload the images . In My photo.rb : has_attached_file :image, :styles => { :original => "", :thumb => "" }, :path => ":rails_root/public/attachments/albums/:album_id/photos/:id/:style/:basename.:extension", :url => "/attachments/album...

Email client within a Rails applicaton

I need my application to have a module with email functionality. This will have all the functionality of an email client. Each user will have an inbox, outbox, sent folder, custom folders, sub folders etc. They should be able to send, receive,forward, reply to emails. Is there any gem/plugin I can use for this? If there is an alterna...

jQuery/Rails: How do I use jQuery to modify submit for multiple forms ending with unique IDs in Rails?

I have a page that creates multiple forms for each object that I had selected on the previous page, and each of these forms has the id "edit_movie_[uid]". I'm trying to get jQuery to act on submit but right now all it does is make my submit buttons nonresponsive. In my application.js I have: jQuery.ajaxSetup({ 'beforeSend': functio...

Can I use controller methods in a observer?

I need to refer to a controller method from a cache observer, How can I make it? ...

Best way to manage date objects?

I have some date objects that are Date of the Date class, and others that are Time. The trouble is is that when I parse them to load them chronologically, they list first as the Times, followed by the Dates. This is the code that loads them : query.any_of do |any_of| any_of.with(:date).greater_than((params[:current_date] || Date...

How do I iterate through a hash where I can view the next key also?

I have a hash of dates to money, and I need to put new money deposits inbetween a set of dates. so, lets say my hash is {"000000001" => "0.00", "000000002" ="12.34", "000000010" => "5.95"} and I want to insert 000000008, 54.34 then my resulting hash should be {"000000001" => "0.00", "000000002" ="66.68", "000000010" => "5.95"} *...

How can I grab certain values in a hash in Ruby?

I have a hash hash = { 1=> { 0=> 'apple', 1=> 'tree'... ....}, 2=> {.....}} I want to grab the 0 for all hashes within the hash. I know there is a transpose for array, but there any way to do this with a hash easily? ...

Are Sequel::Model validations only instance methods?

In modern versions of ActiveRecord you can define any number of before_validation handlers using a simple declaration: class MyModel < ActiveRecord::Base before_validation :do_something before_validation :do_something_else end Using Sequel it looks like the only way you can do this is similar to the older ActiveRecord method: cla...

Reading cookie value in Rails

I successfully set a cookie in JavaScript: var date = new Date(); date.setTime(date.getTime()+(1*24*60*60*1000)); //one day expiration date var expires = "; expires="+date.toGMTString(); window.name = date.getTime(); document.cookie = "window_name="+window.name+expires+"; path=/"; Then in rails I try to read (I've tried both of the fo...

Testing a conditional validation with remarkable

I have a rails model with this validation: validates_numericality_of(:insert_oz, :allow_blank=>true, :greater_than=>0, :if=>(proc do |note| !note.insert_pages.nil? && note.inser...

Ruby on Rails: Problem adding Transient Attribute to Object for JSON Serializaton

Hi everyone, In my Item controller, I wish to add a transient (i.e. non-persistent) attribute to my model object before rendering it as JSON. def show @item = Item.find(params[:id]) @item.comment = "some comment" render :json => @item end My Item class looks like this: class Item < ActiveRecord::Base attr_acc...

In Ruby on Rails, how to create a record with ID 3 when it was destroyed earlier?

I am trying an experimental Rails project and destroyed record 3 (ID == 3), so now there is record 1, 2, 4, and 5. Is there a way to repopulate this table with record ID from 1 to 5? (this is using mysql) I can use if Item.exists?(i) item = Item.find(i) else item = Item.new end # set some values item.name = "haha" + i item.save...