how to make api call to fetch json data from a url

i am trying to fetch a json data in my rails app from a url. how to make this api call. { “name”: “MagicList”, “count”: 20, “frequency”: “realtime”, “version”: 5, “newdata”: true, “lastrunstatus”: “success”, “lastsuccess”: “Sat Apr 26 2014 14:34:40 GMT+0000 (UTC)”, “results”: { “collection1”: [ { “Title”: { “href”: “http://www.magicbricks.com/propertyDetails/2-BHK-746-Sq-ft-Multistorey-Apartment-FOR-Sale-Sector-79-in-Gurgaon&id=C0gt4k2Fa9tzpSvf+uAgZw==”, “text”: “2 BHK Multistorey […]

Ruby – Get file contents with in a separator in an array

I have a file like this: some content some oterh ********************* useful1 text useful3 text ********************* some other content How do I get the content of the file within between two stars line in an array. For example, on processing the above file the content of array should be like this a=[“useful1 text” , “useful2 […]

This Rails code works in Ruby 1.8.7 but not 1.9.2

Edit: This works: <%= form_for (@quiz_attempt.blank? ? QuizAttempt.new(:patient_id => current_user.id, :started => Time.now.utc, :step_quiz_id => @course_step.step.step_quiz.id) : @quiz_attempt), :url => submit_quiz_course_course_step_path(@course_step.course, @course_step) do |f| %> But this doesn’t: (Trying to use form_for with as a function form_for() <%= form_for ((@quiz_attempt.blank? ? QuizAttempt.new(:patient_id => current_user.id, :started => Time.now.utc, :step_quiz_id => @course_step.step.step_quiz.id) : @quiz_attempt), :url => submit_quiz_course_course_step_path(@course_step.course, […]

incompatible character encodings: UTF-8 and ASCII-8BIT in render action

ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT): app/controllers/posts_controller.rb:27:in `new’ # GET /posts/new def new if params[:post] @post = Post.new(post_params).dup if @post.valid? render :action => “confirm” else format.html { render action: ‘new’ } format.json { render json: @post.errors, status: :unprocessable_entity } end else @post = Post.new @document = Document.new @documents = @post.documents.all @document = @post.documents.build end […]

Rails API Paperclip. Uploading image converting it to base 64 and saving it and retrieving it

Hello i am creating an api using Ruby on Rails. I am using paperclip gem. I have a profile model that has an avatar. How do i go about allowing a user to upload an avatar? Currently im quite lost. Problem is i can get this architecture to work. I am quite beginner so any […]

FileUtils.mv adding linebreaks in Windows

I am streaming wav data from a flash application. If I get the data and do the following: f = File.open(‘c:/test.wav’, ‘wb’) f << wav_data.pack(‘c’*wav_data.length) f.close The wav file works perfectly. If I do this: f = Tempfile.new(‘test.wav’) f << wav_data.pack(‘c’*wav_data.length) f.close FileUtils.mv(f.path, ‘c:/’) The file is there, but sounds all garbled. Checking in a […]

how to parse and display hstore key/value in rails

I’ved got a data type that is postgres hstore that stores a json string. I want to be able to parse and display the key/values on rails html page. Somehow, I just do not know how to run a parse on the data field and display each one of key/value listed in the string. <% […]

How to wait for Thread notification instead of joining all the Threads?

In few words, a user makes a request to my web service, and I have to forward the request to X different APIs. I should do it on parallel, so I’m creating threads for this, and the first Thread that answers with a valid response, I should kill the rest of the threads and give […]

Unable to add Impressionist model to Solr

To keep track of unique views I added impressionist gem. The impressions table will grow at a faster rate due to higher traffic. This will cause problems later when I want to show a comparison between consecutive weeks/months. So I thought of linking impression’s model with solr. To implement this I first created a model […]

How to install gems based on Gemfile.lock (without Gemfile)

Usually, people will use bundle install to install gems. But it require Gemfile and Gemfile.lock(optional). My situation is a little different. I only have Gemfile.lock. So how can I install all these gems based on bundle command. I tried bundle install –deployment. But I got Could not locate Gemfile error. OK. I asked this question […]

Ruby is the best programming language in the world - Ruby on Rails.