ruby-on-rails

Location based URL routing in Rails

Hi everyone, I am new to rails. I want to know more about IP based Location, GeoLocation URL routing. I have 2 questions. The first one.. Based on the location of the country, how to you have URL routing? If my IP is from USA, I should be directed towards USA homepage. If I am from UK, I should be directed from UK homepage. If I...

how to simulate raw_post in rails?

rails controller has raw_post, what is the behaviour of the raw_post? how to simulate the external request.raw_post? ...

remove <font> tag using hpricot

the html like this: "[font color="#FF0000"]test [font color="#FF0000"]Hello world[/font][/font]" I want to replace the font tag the result like this: test Hello world thanks you ...

Has many relationship help in rails

I have two models questions and answers. and a question has_many answers. How can I find out all the questions which don't have any answer? ...

Rails : How to connect the psql database with Rails Web application

I am new to Rails database operation. I want to know , how to connect the psql database with my Rails Web application. For example I just wanted to display some table information in rails web page. What do I have to do? Any idea or any tutorial to learn ...

Can Ruby on Rails cache a Controller "as long as code is not changed"?

At work, we have a situation where when script/server is run, then all the controller code is cached. This is to speed up the development server. But that will mean that whenever we change the controller code, we need to restart the server. So we can turn off the caching of controller code all together. But can't there be mechanis...

jquery form plugin / rails file upload / plain text respond instead of html

Hello, i'm trying to get a file upload via ajax form to work.. as i am using the jquery form plugin the file upload works well.. but the rendered html in the respond_to js block is returned as plain text. hope someone can help controller: if @visitreport.save flash[:notice] = "Der Besuchsbericht wurde erstellt." respond_to...

elaborate urls with regex

i have a string that maybe contains text with links. I use these instructions for elaborate it: message = message.gsub(/http[s]?:\/\/[^\s]+/) do |m| replace_url(m) end if the string is "http://www.youtube.com/watch?v=6zToqLlM8ms&amp;amp;playnext_from=TL&amp;videos=qpCvM5Ocr3M&amp;feature=sub" the instructions works. b...

How to build batch processes with rails

I'm using ruby on rails 2.3.8 and I'm kind of knew at this technology. I'm using Windows 7, but I'm planning to hire a Linux hosting soon. I'd like to know how to build processes that runs every night for things such as: checking stuff in the db, update values, send newsletter emails, etc. ...

Syntax for loading observers (in a model subdirectory) in environment.rb?

I have a lot of model observers, so I want to organize them in a subdirectory under the model folder. model --> observer --> user_observer.rb, activity_observer.rb, etc. Prior to placing in the subdirectory, I was loading the observers like this: Rails::Initializer.run do |config| config.active_record.observers = :user_observer, :...

Could someone give me an example of node.js application

Guys, I'm trying to understand the differences between some of the newer web programming frameworks that now exists, namely Node.js, Rails, and Sinatra. Could someone give me an example of applications that would work best on each of the frameworks? That is to say, what is an application that would be best suited for Node.js as oppose...

Webrat and Rails: Using assert_contain after click_button gives me "You are being redirected"

I'm writing an integration test for a rails application using webrat. After filling out a form, the user presses submit and an account is created. click_button "Submit" assert_contain "Your Account Has Been Created" However, the test fails: expected the following element's content to include "Your Account Has Been Created": You are ...

Convert .pdf to images using RMagick & Ruby

I'd like to take a pdf and convert it to images...each pdf page becoming a separate image. There's a similar post here: http://stackoverflow.com/questions/65250/convert-a-doc-or-pdf-to-an-image-and-display-a-thumbnail-in-ruby But it doesn't cover how to make separate images for each page. ...

Dealing with date and time functionality in Rails

Hi guys, I have a date in the database and I want to export it to DATE_TIME.civil() format like the one shown below (I am doing this to export it to a .ics calendar file) DTSTART:20100605T083000 DTEND:20100606T083000 I have two fields in the database one called start_date and two fields start_time and end_time. I want to add...

rails restful routing - single index with nesting

Hi I'm working on a rails application which is built around a tree data structure. As such, the index of the controller displays the root node of said structure. Demonstration is probably easier to explain what I want: /place/1 == place can I restfully define such that /place/1/photos == place/photos and /place/1/photos/1 == plac...

how to tell autotest to correctly track changes in app source?

Hello, I want to get autotest to run Steak acceptance tests whenever one of my rails app's relevant files is changed. After studying Rspec's and Cucumber's own autotest configs, I'm trying the following mappings: Autotest.add_hook :initialize do |at| at.add_mapping(%r%^spec/acceptance/.*_spec.rb$%, true) { |filename, _| filename...

how to use content_tag in a lib/class

Hi all, my problem: I want to create a class TitlePanel in my lib folder that class uses the content_tag method but I can't figure out how to load it. I have tried all require 'xxx' that I could think of and it keeps giving me error messages that it can't find the required file. Basically, what I am trying to do is create a helper that...

Setting up PayPal to allow my site's members to charge others

I have a site where members write specialized articles. I'd like to allow my members the option of putting up a PayPal button to charge their readers for these articles. Basically, I'd like to set it up so that a member can choose to charge for content or not. If they choose to charge for an article, then their reader must pay via P...

Partial template submit_tag

Hello, I would like to create a login field everywhere on the top of my page, so I've add a : in application.html.erb : <%= render :partial => 'sessions/new' %> in .../views/sessions/_new.html.erb <%= form_tag do %> <div> <label for="name">Email :</label> <%= text_field_tag :name, params[:name] %> <label for="password...

Have Rails 2.3.x ignore the i18n gem

I have a Rails 2.3.5 project that uses the localization features of Rails. I also happen to have Rails 3 beta installed (which depends on the i18n gem). Rails 2.3.5 will happily handle localization on it's own (without i18n installed), however if the i18n gem is available, it makes use of it. Recently I upgraded my gems and now have ver...