ruby-on-rails

Can someone provide an example for how to post XML using HTTParty and Ruby on Rails?

Hi All, I need to post some xml to a webservice and I'm trying to use HTTParty. Can someone provide an example as to how I go about doing so? Here is the format of the XML I need to post: <Candidate xmlns="com.mysite/2010/10/10" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt; <FirstName></FirstName> <LastName></LastName> <Emai...

Ruby on Rails 3 Submit Form with a button

Submiting a form <%= submit_tag %> Is there anyway to submit aform using a button instead of the submit_tag? Nor do I want to use the image_submit_tag. What other options do I have to submit a form? I understand that the submit_tag produces <input type="submit">. Thanks in advance. Edit: I'm interested in reusing some of my css....

Passenger showing blank 200 OK responses when it should be showing 404sA

(Using Rails 2.3.9 and this happens both with passenger-2.2.15 and passenger-3.0.0.pre3.) Does any know how I could be getting blank pages with status 200 for requests that should result in 404s? I see in log/staging.log ActionController::RoutingError... but in my passenger access.log it's showing 200 OK ...

Devise : Using Devise Oauth info for facebook interactions.

I have gotten Oauth working with Devise and my users are happily logging in using their Facebook accounts. I would like to allow the users to "like" certain things on my site and post stuff back to their profiles. How do I do that using the information I have (seemingly only an encrypted_password and password_salt)? ...

How do I properly gem unpack a gem in a rails application?

I tried rake gems:unpack rake gems:unpack:dependencies Then i ran rake gems:refresh_specs which gave me this error undefined method `installed_source_index' for #<Gem::SourceIndex:0x100549718> then i ran this rake gems:install Then i ran script/console and tried to use the gem and error ITunesSearchAPI.lookup(:id => 3996...

ActiveRecord touch(:column) always also updates :updated_at

I've got pretty much the same problem as this guy: http://www.ruby-forum.com/topic/197440. I'm trying to touch a column (:touched_at) without having it auto-update :updated_at, but watching the SQL queries, it always updates both to the current time. I thought it might be something to do with the particular model I was using it on, so ...

rspec error 'report_activate_error': Could not find RubyGem rspec-core (>=0) (Gem:LoadError)

Hey all, I have a seemingly simple error but I can't seem to figure out what to do to resolve it. I have tried uninstalling and reinstalling but that hasn't helped me out. I am new to the terminal and to ruby/ruby on rails, so forgive my potentially stupid question. Does anyone know how to resolve this issue? This is the exact error me...

How do you access sessions and cookies from within a Rails gem or lib?

Im trying to create what will eventually be a rails gem (right now I have the files within the /lib directory) and I need to be able to read/write to and from cookies and sessions. My methods will be called from within either the controller or views, so access to the cookies and sessions SHOULD be possible from within my gem but I cant ...

Rails: problem with plugin

Hello friends! My new app work with my small custom plugin (located in RAILS_ROOT/vendor/plugins/) The problem is what plugin-init file make some actions like this: ModelName.all As you can see this is just a simple query. The problem is, when i try to do rake-task: "rake db:migrate", i have some bad error: Mysql::Error: Table 'sh...

Event lost in ajax callback

I'm have a Rails 3 app that uses Prototype. I create a form with: =form_for :appt, :url => { :controller => "appts", :action => 'create' }, :html => { :id => "apptform" }, :remote => true do |f| That controller returns some json: render :json => @appt Some javascript waits til the dom is loaded, then sets some observers: document...

Is MongoDB's query or Mongoid's API good for filtering 2000 items from a total of 80,000?

The idea is to do analytics of 30 or 2000 products out of a collection of 80,000 products. Say, if there are 80,000 products, and to get the top products with highest number of pageviews in a category, which can include only 30 or up to 2000 products, so we can either filter out all those products first, and then use map/reduce to find ...

ActiveRecord Rollback does not work in Rails test

Throwing ActiveRecord::Rollback works, but not in tests. I've had this problem before, am now having it again, and for some reason can't find any record of someone else having this problem. I'm this is because tests do a rollback each time a test runs, and most databases don't support nested rolllbacks. However, I can't be the only pe...

Ruby on Rails Hash cannot be converted to string error

Can anyone add meaning to this. I installed the restful_authentication plugin and when i tried to run the rails server, this poppedup. I get the same error having tried to manually remove the plugin and when i run all rails commands: rake, plugin install, plugin remove, etc. Any ideas? rails server => Booting WEBrick ...

Finding unique hash value within array of hashes (Ruby)

a[0] = {:id => '1234', :value => '37'} a[1] = {:id => '4321', :value => '50'} a[2] = {:id => '1122', :value => '50'} From here I want to be able to check to see if a hash exists with :id => '4321' without having to loop through the array manually. Is there anything where I can do something like this: a.exists?(:id => '4321') ? I've t...

No method error in rails 3 app

I'm getting this error: undefined method `post_comments_path' for #<#<Class:0x1052a6e98>:0x1052a4be8> Extracted source (around line #27): 24: 25: <% end%> 26: 27: <% form_for [@post, Comment.new] do |f| %> 28: <p> 29: 30: <%= f.label :name, "Author" %><br /> My routes: Myblog::Application.routes.draw do root :to => ...

Delete link sends "Get" instead of "Delete" in Rails 3 view.

I'm using Rails 3 and have have a page that outputs a list of posts from the database. I'd like to be able to delete a post from a link. The 2nd example below works, but the first doesn't. Anybody know why the first won't work? My view contains: # this link sends a "GET" request which asks for the #show function <%= link_to 'Delete',...

From an action, get a post variable, output to page, then halt execution

Is it possible to grab a post variable in a action, output it to the screen, and then halt execution? in asp.net I would do: Response.Write (Request.Form["blah"]); Response.End(); ...

Is it possible to integrate a nodejs app as a part of a rails app?

What's the best way to integrate a NodeJS app into an existing Rails app? Rails app: http://www.rails.app Nodejs app: http://node.rails.app or even http://www.rails.app/node 23-09-2010: After searching for some time, I think an approach would be to have 2 separate services: Rack (Rails) service, which would host the rails applicatio...

Ruby on Rails Labels

Why do we use labels in rails? such as in a form_for, f.label f.text_field When you don't use labels, everything still works. So why use them? ...

rails to_json unexpected behavior for include_root_in_json

Hi - I have a model like this class Parent < ActiveRecord::Base :has_many :kids end class Kid < ActiveRecord::Base :has_many :grandkids :belongs_to :parent end I can generate json like this: the_parent.to_json( :methods => [:kids] ) => { "parent" : { "kids" : [ { "kid" : { "name" => "kid0" .... and so on. Just what I want. ...