ruby-on-rails

Conditionally Strip HTML Node - Regexp/gsub

Hi I want to generate a search preview of an article by removing certain html nodes including the child node(s) (particularly headers and images) and removing all other tags eg. paragraph while leaving child nodes. e.g. "<h2>Subject</h2><p>Subject is the who, what, where, why and when.</p>".gsub(/<\/?[^>]*>/, '') results in Subject...

/usr/local/lib/libz.1.dylib, file was built for i386 which is not the architecture being linked (x86_64)

Hi, having this problem on installing several things on my mac, i think this problem is coming from upgrading my leopard to snow leopard. Also this problem also is linked with macports i think. /usr/local/lib/libz.1.dylib, file was built for i386 which is not the architecture being linked (x86_64) Any ideas? Update To be more speci...

Ruby on Rails rake db:drop

Hi, Is there a command to drop a specific table in the database and not all of them? Or a way to update a database table Thank you. ...

I'm looking to develop a simple two player online turn based game using ruby on rails. Any tips

I am looking to knock off a quickie rails app that will allow two players to take turns and get feedback after each turn - approximately 10 rounds of turns so there are no issues with long lived connections. I want to use rails because I know it reasonably well, have hosting already set up and have my tools installed. Do you have any a...

Ruby/Rails Simple search form and white spaces

Hi, I've implemented a "simple search form" (railscasts #37) in my app, but I wonder how: 1.) I cannot display any results if the keywords field is empty, or if the index page is loaded (I've tried search != "". Maybe there is a better way) 2.) I can add a function which avoid multiple white spaces in the search. (if users wrote someth...

Can not write permanent cookies

I experimented the permanent cookies shortcut with Rails 3.0 (and Ruby 1.9.2) but I can't write in this hash. I try with the following code : cookies.permanent[:last_used_expiration_delay] = @snippet.expiration_delay But the hash remains empty (here is the YAML dump) : --- !map:ActionDispatch::Cookies::PermanentCookieJar {} Basic ...

Override application tests on rails plugin

I created a plugin for a OS Rails Project. The plugin makes the tests fails, in order to preserve the system consistency, i would like to override the app tests which fails once the behavior of my plugin is applied. I have created patches to modify the methods of some existing classes through patches in Class and Instance methods, and I...

Undefined method `persistence_token_changed?'

Hi, complete noob here! Despite following the Railscast authlogic tutorial step by step, I'm running into an error when I try to register a new user. NoMethodError in UsersController#create Undefined method `persistence_token_changed?' for #<User:0x23d1c54> My Users controller code is as follows: class UsersController < Applicati...

How to send all email from a Rails app asynchronously

I have a rails app that uses delayed_job. Whilst DJ gives me a really easy way to setup delays on emails, is there any way to globally configure my app to send all email asynchronously regardless? The reason for this is that I have some gems that send email and don't want to have to modify them to accept DJ. ...

Extract to Rails helper

I want to make this thing more generic. <%= form_for :page, :url => { :action => :create } do |form| %> <div class="tabs"> <ul> <% languages.each_with_index do |lang, i| %> <li><a href="#tabs-<%= i+1 %>"><%= lang %></a></li> <% end %> </ul> <% languages.each_with_index do |lang, i| %> <div id="tabs-<%= i+1 %>"> <field...

How to integrate openId with devise in rails 3

I'm new to rails and just got a simple devise setup working. I'm looking to implement something that still uses the core devise feature set but would allow login via openid provider rather than "register w/ email or username" How might I get started with this using the latest devise gem and rails 3? ...

How to tell an ajax request in ruby

IN PHP its like this but in Ruby is how if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest") { }else{ // header("Location: " . base_url()); } ...

undefined method `to_sym' for nil:NilClass during a db:auto:migrate

I'm trying to run a db:auto:migrate in my system and it keep throwing the undefined method `to_sym' for nil:NilClass whenever it gets to a column that uses a type of date. If I change the field to a datetime and run the migrate, it will change the field to a date with no errors. What is causing this problem. I have to keep changing th...

rails controller respond_to format with two extensions (e.g. tar.gz)

Is there a mechanism or accepted approach for responding to requests that have a more complicated format extension? My specific scenario involves returning a plist file. However, I need to sometimes return this file as an XML plist file and sometimes as a binary plist file. I thought that URLs composed like /resources.xml.plist and /re...

problem using rails & money gem

I have a new app (Rails 2.3.8) that uses lots of money fields. I'm using the money gem (3.0.5) and the acts_as_money plugin. I've written a number of rspec model examples and everything seems to be working fine there. My problem is in defining forms for new & edit. As I've done in past projects for complex layouts, I extracted the basic...

rake tasks are not discovered in rails 3

Hi, I have trouble getting started with rails 3.0.0, because it just doesn't load the rake tasks rake gems:install rake aborted! Don't know how to build task 'gems:install' rake -T rake about # List versions of all Rails frameworks and the environment rake db:create # Create the database from config/database.ym...

Creating and Extracting a tgz archive in Rails

Does anyone know how to archive a folder and its contained files as a tgz archive using Rails? What I would like todo is archive the contents of the folder and then have another script which extracts the same folder that was archived. All of the archiving techniques that I've come across are pretty complicated, I was wondering if there ...

Rails: Query to get recent items based on the timestamp of a polymorphic association

I have the usual polymorphic associations for comments: class Book < ActiveRecord::Base has_many :comments, :as => :commentable end class Article < ActiveRecord::Base has_many :comments, :as => :commentable end class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end I'd like to be able to define ...

Ruby/Rails Conditional search method (if ... else "no results found")

Hi, Here is the code of a "simple search form" (thanks to jordinl) which I try to improve. I would like to add the case if there is no match found. So, there is the view (views/users/index.html.erb) <% form_tag users_path, :method => 'get' do %> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", :name => nil ...

Rails::Railtie: Trouble creating a Rails 3 gem

I could really use another set of eyes on this so I thought I would post it here. A while ago I wrote a basic ActiveRecord Extension for my own educational purposes. I've been reading about Railties lately and thought I would try to get it working with Rails 3. I thought I would package it up as a gem to get a sense of that process as we...