how to convert strings like "this is an example" to "this-is-an-example" under ruby
The title is my question, thank you in advance for your answer! ...
The title is my question, thank you in advance for your answer! ...
I'm learning VIM for Rails development and would like to easily navigate methods in a file. So far I see several options: Find 'def' by using /def<space> Create a macro that corresponds to a key using q and record use VIM marks? (not even sure what they do, they just sound promising Anyone have any better ideas? ...
I'm running into problems implementing statuses for a model. This is probably due to wrong design. There is a model which has a status. There can be multiple instances of the model and only a few predefined statuses (like: created, renewed, retrieved etc.). For each individual status there is some calculation logic for the model. E.g. m...
I have page with js that post data via XMLHttpRequest and server side script check for this header, how to send this header? agent = WWW::Mechanize.new { |a| a.user_agent_alias = 'Mac Safari' a.log = Logger.new('./site.log') } agent.post('http://site.com/board.php', { 'act' => '_get_page', "gid" => 1, 'order' => 0, ...
Is there a way in which I can create a serial number (SNO) column through scaffolding in Rails which increases on adding a record, decreases on deleting a record and cannot be modified manually? ...
I've written this ruby program to send a UDP Packet to port 16800: require 'socket' sock = UDPSocket.new sock.bind("", 47123) sock.send("Hello!", 0, "192.168.0.100", 16800) sock.close where 192.168.0.100 is my own ip address. However, the packet doesn't show in Wireshark and my UDP server listening on port 16800 on the same PC (runni...
I have a class that has a number of modules that are mixed in with it based on some runtime criteria. I want to be able to get a list of what modules have been mixed into this class. How can you do that? UPDATE So when I said class I meant object as it is the object that is being extended at runtime using: obj.extend(MyModule) obj....
In my apps/controllers/model_controller.rb I have (names of models/methods changed to protect the innocent): def background_sync @background_task_uid = Model.async_process_model_cache({:name => 'name'}) @model_sync = ModelSync.new # Adds a new record in the queue of pending jobs @model_sync.process_id = @background_task_uid # Puts ...
I am trying to load in my data migration a member database. Quite a few of the names have special characters such as "Ciarán". I've set up a simple example like this: require 'rubygems' require 'fastercsv' FasterCSV.foreach("/Users/developer/Work/madmin/db/data/Members.csv") do |row| puts row.inspect end and I get the following: ...
I happen to be working in a sandboxed Ruby environment and have been trying to add libraries to it with mixed results. However, it has raised some interesting questions about how Ruby works. I'm looking to understand how Ruby links libraries and how it decides what to load when it starts up. What is going on when I do a require 'someLi...
How do you tell a Ruby program to wait an arbitrary amount of time before moving on to the next line of code? thanks ...
Hi people! I haven been all day training to fix this problem but i couldn't. The question is easy, i don't want to put anymore the require 'rubygems' line everytime i require a gem... If i put the require 'rubygems' before any other "require" the file runs perfect but if i don't put the require 'rubygems' line the following error occur...
This is for an already existing public API that I cannot break, but I do wish to extend. Currently the method takes a string or a symbol or anything else that makes sense when passed as the first parameter to send I'd like to add the ability to send a list of strings, symbols, et cetera. I could just use is_a? Array, but there are oth...
In my application, these "planners" (essentially, article ideas) follow predetermined templates, written in Markdown, with some specific syntax here: Please write your answer in the following textbox: [...] Please write your answer in the following textarea: ...So here, on line, you should write one thing. ...Here, on line 2, you shoul...
I have a need to mark packets with DSCP markers for testing a product, but I'm not seeing a way to do this directly. Am I just missing something, or do I really need to start learning network programming in C to get this done? Or, which may be easier, is there a program out there (for Linux) that will send data with DSCP markers better...
What are the best Ruby / Rails book available right now ? Note : I know that this question has probably been asked before. But things change so much in the Ruby / Rails world that some of the books are not up to date or even teaches things that are deprecated in the newer release of Ruby / Rails. ...
I have a Flickr interface that I wrote a while ago and part of it bothers me and I'd like to make it nicer. The way it works is I use method missing to construct the url parameters for the flickr call from the methods called on the flickr object, eg. @flickr.groups.pools.getPhotos(:user_id => "12656878@N06", :group_id => "99404851@N00")...
A while ago I asked (Joins across multiple tables with ActiveRecord with named scopes) http://stackoverflow.com/questions/1189086/joins-across-multiple-tables-with-activerecord-with-named-scopes Now I need to create a named scope that involved joining across more than two tables, eg: named_scope :baz_category, lambda {|c| {:joins=>([:f...
This blog post of December 2008 says that rubygems is broken on Debian-based systems. Does rubygems work cleanly on Ubuntu (for both 1.8 and 1.9)? ...
Hi, I have code in view <% uberform_for :profile, :html => { :multipart => true, :method => :put }, :url => update_avatar_path do |f| %> <%= f.file_field :avatar %> <p><%= f.submit 'Upload avatar' %></p> <% end %> in controller def update_avatar current_user.profile.update_attribute(:avatar, params[:avatar]) redirect_...