ruby-on-rails

How do you specify Content-Type (and other headers) and request body in RSpec Rails Controller test?

I'm trying to test a rails action that takes raw json in the POST body. If i curl with the Content-Type: application/json header set, rails parses the params correctly. How do you set the request body and headers directly in an rspec controller test? ...

Can you explain what this code snippet does?

I just got finished watching a railscast episode #189 and the was using a bit_mask to store a value in the users table. I am trying to implement the same thing but when I test via irb I am getting errors. First can someone explain what this is actually going. I know what the first line is doing and part of the second line ROLES = %w[adm...

finding friends in a rails app via facebook, gmail, twitter, etc...

Hello, I have built a social networking app in rails, and am looking for a simple way to allow users to login to their various other accounts (OAuth?) such as facebook, twitter, gmail, other mail clients, etc and see if their friends/contacts on those sites are signed up for my site. Additionally I will be adding functionality to allo...

RoR UI for Readonly Emails

Hello, I am build a application to pull incoming emails from a mailbox and display them in read_only mode to users. Users should NOT compose any emails but just readonly access to email list and email content. It should support both text and rich text html emails as well as attachments. Can you please advise me how to go about this? T...

Is the ruby on rails webrick server ever used in production?

In a situation where the main server (apache) is offline, is it ever acceptable to run the ruby on rails application on the built in webrick server? Or should I have a local apache running. I have to have it available local and it would be very rare it ever ran local but if I had to would it be best to go ahead and install apache or ha...

Merging tags with acts_as_taggable_on Rails gem

I'm using acts_as_taggable_on in my Rails app, and I'd like advice on the best way to merge two tags. For example, if I've got a list of Food records, and some are tagged "cheese" and some are tagged "milk," what's the best way to combine these tags into a single "dairy" tag. Should I just find all records tagged with "cheese" and/or ...

rails3 session store

Hi, could you tell me plz - how to use in rails3 application external Active Record session store? In rails2 its simply ActiveRecord::SessionStore::Session.establish_connection("sessions_#{RAILS_ENV}") but wat about rails3? ...

accepts_nested_attributes_for with find_or_create?

I'm using Rails' accepts_nested_attributes_for method with great success, but how can I have it not create new records if a record already exists? By way of example: Say I've got three models, Team, Membership, and Player, and each team has_many players through memberships, and players can belong to many teams. The Team model might th...

Defining methods on the fly in Ruby / Rails - how to set params?

I am trying to define a set of functions where I can pass in given params. for example, how do i do the following? >> get_1_type("xxx") V4_RELATIONSHIP_TYPES=[1=>2,3=>4] V4_RELATIONSHIP_TYPES.keys.each do |key| self.class.send(:define_method, "get_#{key}_type".downcase) do return GuidInfo.get_or_new(PARAMS, V4_RELATIONSHIP_TYPES[...

RoR set value for textarea

Hi, I cant seem to figure out how to put text in between the generate textarea tags. Is there a way to specify a value in the RoR textarea tag that will be placed between the generated textarea tags? This is an example of the code I am using. <% remote_form_for ... do |f| %> <%= f.text_area :message, %> <%= f.submit 'Upda...

rails sortable list not updating

I have followed the instructions on http://railscasts.com/episodes/147-sortable-lists for creating a sortable list. The list drags and drops as it is supposed to, but the sort action is not being fired when the link is released. I have tested this by putting a render :text command into the sort. No error's appear, it just doesn't fire ...

how to unescape \\ in a regex that has been escaped by Rails?

Hi! I'm trying to store regexes in a database but they're getting escaped by rails. For example \w*\s\/\s becomes \\w*\\s\\/\\s in the database and when retrieved. I'm inserting trying to use them with mystring.sub(/#{regex_variable}/, ''), but the escaped regex is not matching as desired. What's the best we to resolve this so the r...

Is Rails good to build web interfaces for programs in languages other than Ruby?

Say, I want to create a web interface for a program or application written in a different language other than Ruby, maybe, Java or C. Is using Rails still a good option ? If so, can anyone give me sources(links to tutorials or books) which I can refer to? Thanks in advance. ...

devise+cancan not blocking access to index problem wherer @proj = Proj.all

Hello, I have an app that uses Devise and CanCan. in the config>initializers>Abiliity.rb class Ability include CanCan::Ability def initialize(user) if user.is? :superadmin can :manage, :all elsif user.is? :user can :read, Project do |project| project && project.users.include?(user) end ...

Rails 3 using Devise: How to allow someone to log in using their Facebook account?

I have a Rails 3 application using Devise for authentication. Now I need to allow someone to log in using their Facebook account. I think this is called Facebook Connect, but I've also heard the term Facebook Graph API, so I'm not sure which one I'm asking for. What do I need to do in order to integrate Facebook Connect with Devise? ...

Stuck: SQL Server + Rails + Mac OS X

I am having an insanely tough time getting Rails to connect to SQL Server on a Mac. I have set up a DSN using Actual SQL Server drivers: http://www.actualtech.com/ - it works great. I can test it and it seems to be functioning. However, when I run: iodbctest "dsn=rails_import2;uid=sa;pwd=mypassword" The output is: 1: SQLDriverConn...

In rails, how to g-zip a combined javascript file which generated by the 'javascript_include_tag'?

I was thinking javascript_include_tag with :cache option would g-zip the combined javascript file automatically: <%= javascript_include_tag 'j1.js', 'j2.js', 'j3.js', :cache => 'js_all' %> But it just generate a file which simply combined all those javascript files in plain text mod; Then how to g-zip the combinded file automatica...

How to implenent mongodb 'includes?' finder condition

I am using Mongoid and have a project and a user model. in the Project model, I have a field class Project include Mongoid::Document field :name field :user_ids, :type => Array end class User include Mongoid::Document field :email end I can find all the users belonging to one project, i.e., 'find this project's users' @p...

I know how to set class methods, but how do I set instance methods on the fly?

I asked a previous question on class methods, but I really want to understand how to do this for instance methods as well. Thanks! =) The code below sets class methods for a given array: class Testing V4_RELATIONSHIP_TYPES=[1=>2,3=>4] V4_RELATIONSHIP_TYPES.keys.each do |key| self.class.send(:define_method, "get_#{key}_type"...

Ruby on Rail's Authlogic gem - password confirmation only for password reset and the edit page

I followed the Authlogic example tutorial at github and have everything set up and running. But I would like to make a change concerning password confirmation. Following the tutorial, you must enter a password confirmation when registering. I don't want that to be necessary, so I put c.require_password_confirmation = false in the acts_a...