I'm referring to http://www.codinghorror.com/blog/2005/10/equipping-our-ascii-armor.html but I'm getting drastically different results.
Does anyone know how to duplicate his blog post examples in Ruby?
I'm currently working on a largish Ruby on Rails project. It's old enough and big enough that it's not clear if all views are actually in use.
Is there any script/plugin out there that can generate a list of unused view files?
I am consuming various XML-over-HTTP web services returning large XML files ( 2MB). What would be the fastest ruby http library to reduce the 'downloading' time?
Required features:
both GET and POST requests
gzip/deflate downloads (Accept-Encoding: deflate, gzip) - very important
I am thinking between:
open-uri
Net::HTTP
curb
but you can also come with other suggestions.
P.S. To parse the response, I am using a pull parser from Nokogiri, so I don't need an integrated solution like rest-client or hpricot.
I am going to be away from the internet for a few weeks and would still like to get a project done. What steps should I take to make sure I have access to the things I need (ruby and ROR) while I will be disconnected?
I've read several other questions about material in order to learn RoR. But my question is can I start learning RoR without Ruby?
It's clear that the other way around is better, but I would rather try this way if it makes sense (somehow). Or learn both in parallel...
I'm making a forum application with various levels of authorization, one of which is a Monitor. I am doing this by extending my User class, and I plan on fine tuning this with "-ship" classes (e.g. administratorship, authorship, moderatorship, etc.). Apparently the Monitor class is part of ruby mixin. How do I keep my resource name without the collisions?
I have an Rails application with SayController, hello action and view template say/hello.html.erb. When I add some cyrillic character like "?", I get an error:
ArgumentError in SayController#hello
invalid byte sequence in UTF-8
Headers:
{"Cache-Control"=>"no-cache",
"X-Runtime"=>"11",
"Content-Type"=>"text/html; charset=utf-8"}
I use Windows 7 x64, Ruby 1.9.1p378, Rails 2.3.5, WEBrick server.
Hi,
I am reading a file that is 10mb in size and which contains some id's. I read them into a list in ruby. I am concerned that it might cause memory issues in the future, when the number of id's in file might increase. Is there a effective way of reading a large file in batches?
Thank you
Does anyone know of a full featured survey tool for rails? Like Limesurvey (PHP -unfortunately for my purposes.)? Tried to look on Ruby-toolbox, but it seems to be down.
Hello,
Hoping to get some feedback from someone more experienced here. I haven't dealt with the dreaded floating-point calculation before...
Is my understanding correct that with Ruby BigDecimal types (even with varying precision and scale lengths) should calculate accurately or should I anticipate floating point shenanigans?
All my values within a Rails application are BigDecimal type and I'm seeing some errors (they do have different decimal lengths), hoping it's just my methods and not my object types...
Thanks!
I want to start my daemon with my application.
In the command line, I can write something like lib/daemons/mydaemon_ctl start to start up my daemon, but I have to do this manually. I want the daemon to start when I start my server (i.e. when the initializer files are loaded).
Is there a ruby command for executing a command line?
Something like exec "lib/daemons/mydaemon_ctl start"?
Thanks!
I am a neophyte with Ruby on Rails but I've created a couple of small apps. Anyway, I'm really interested in OpenID and I would like to implement OpenID authentication and maybe some Sreg stuff in a Rails app. All of the research that I have done has come up with articles that are out of date or just don't work for me. Since I'm so new to Rails I'm having difficulty debugging the issues so...
What is the best way to implement OpenId in Rails?
Thanks
What is the best way to allow for the adding of images and embedding of video in the body:text field of a Ruby on Rails blog.
I understand that I can use an attachment like Paperclip to add a photo to a record but I am wondering how to get images/vids into the actual body of the post.
`<main>': uninitialized constant Object::Nakogiri (NameError)
I get that message when trying to run a simple code (ruby test.rb):
require 'rubygems'
require 'nokogiri'
require 'open-uri'
url = "http://www.walmart.com/cp/Baby-Days/1035659?povid=cat14503-env172199-module122910-lLinksptBABY"
doc = Nakogiri::HTML(open(url))
puts doc.at_css("title").text
I have the gem installed:
~/Code $ gem list --local | grep nokogiri
nokogiri (1.4.4, 1.4.3.1)
Is there a way to access ruby variables in sass or do i have to make a custom function for it?
What im trying to do is to generate a stylesheet for each user so in the controller, i do something like:
def show
respond_to do |format|
format.css{render :partial => "styles"}
end
end
then in the view name _styles.haml i do this:
:sass
#header
:background url(user.banner.url)
is this possible at all?
i'm trying to implement an id obfuscation scheme, with a simple hash borrowed elsewhere. i've added a method on the application helper:
@@M_ID = 2**31-1
@@PRIME = 1580030173
@@PRIME_INVERSE = 59260789 # (calculated from MAXID and PRIME offline)
def obfuscate_id(x)
if x
return ((x * @@PRIME) & @@M_ID)
else
x
end
end
for some reason, whenever this is called, ruby locks up, and starts eating up disk space on my mac... like - gigs of it. any ideas?
how can I eliminate duplicate elements from an array of ruby objects using an attribute of the object to match identical objects.
with an array of basic types I can use a set..
eg.
array_list = [1, 3, 4 5, 6, 6]
array_list.to_set
=> [1, 2, 3, 4, 5, 6]
can I adapt this technique to work with object attributes?
thanks
Ok here's my problem in a nutshell I've built a web service from ruby on rails. I'm using restful_authentication to create and run the login but I'm also building an iPhone application to access my web service but I can't quite figure it out. I was wondering if anyone could help me figure out a place to begin.
Ok, I have been suck on it for hours. I thought net/imap.rb with ruby 1.9 supported the idle command, but not yet.
Can anyone help me in implementing that? From here, I though this would work:
class Net::IMAP
def idle
cmd = "IDLE"
synchronize do
tag = generate_tag
put_string(tag + " " + cmd)
put_string(CRLF)
end
end
def done
cmd = "DONE"
synchronize do
put_string(cmd)
put_string(CRLF)
end
end
end
But imap.idle with that just return nil.
I am trying to find the difference in time (without days/years/months) of two different days.
Example:
#ruby >1.9
time1 = Time.now - 1.day
time2 = Time.now
#code to make changes
#test:
time1 == time2 # TRUE
My solution:
time1 = time1.strftime("%h:%m").to_time
time2 = time2.strftime("%h:%m").to_time
#test
time1 == time2 #True
#passes
I was wondering if there was a better way of doing this? Maybe we could keep the Date the same as time1/time2?
I am new to Rails and I am using Ruby version 1.9.3 and Rails version 3.0.0.
I want to print an array in Rails. How do I do that?
For example, we have to use print_r to print an array in PHP:
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
Output:
<pre>
Array
(
[a] => apple
[b] => banana
[c] => Array
(
[0] => x
[1] => y
[2] => z
)
)
</pre>
How do I print an array in Rails?
I'm creating a Rails app for students and high schools and I'm having some trouble with my User.rb.
I want to have a user model to be used for logging in, but having that user have many roles. The tricky part is that I want users that have a student role to have_one student page, and those that have a role of principal to have_one high_school page.
The students and also nested in the high_school so the entire thing becomes a big mess.
So my question(s): How do I limit a user to only creating one student / high school to represent them? Also how would I nest this student pages inside the highschool without screwing up the user system?
My environment: Rails3 and Ruby 1.9.2dev
Thank you!
I've got some problems running capybara-webkit with the Headless gem, Xvfb and our ci server. We use this setup for automatic integration testing and javascript testing of our Ruby on Rails 3.2 app. During the tests it complains that
webkit_server: cannot connect to X server
But when I ps aux | grep Xvfb
deploy 1602 0.0 0.1 61696 1912 pts/2 S+ Jul10 0:00 /usr/bin/Xvfb :99 -screen 0 1280x1024x24 -ac
I see the Xvfb running. If I run the tests with --trace it also only shows the error log above and I can't debug the error.
Any ideas how I could get some more information, or even a solution?
I'm following the Kevin Skoglund tutorial Ruby on Rails 3 Essential Training, which was written for rails 3.0, though I am currently using 3.2. It uses the following method in the pages_controller with a before_filter to display only the pages which belong to the parent subject.
The tutorial explicitly uses .find_by_id because if the result is nil it "will not return an error". However I get the "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id" error when trying to view a page where @subject has been set to nil.
def find_subject
if params[:subject_id]
@subject = Subject.find_by_id(params[:subject_id])
end
end
The actual code that is causing the error is:
def list
@pages = Page.order("pages.position ASC").where(:subject_id => @subject.id)
end
Is this something that has changed since 3.0? If so, what would be the correct way to implement this functionality in 3.2?
I am using Ruby on Rails 3.0.7 and I would like to use the pluralize method in a my model file in order to properly build custom error messages.
For example, I would like to do something like the following:
NAME_MIN_LENGHT = 2 # Is 2 but I plan to change that (maybe dynamically... if it is possible) in future development
validates :name,
:length => {
:minimum => NAME_MIN_LENGHT,
:too_short => "is too short (minimum is #{pluralize(NAME_MIN_LENGHT, "character")})",
},
How can I do that? Is it advisable? Why?