Search Results

Search found 9825 results on 393 pages for 'ruby on rails3beta'.

Page 54/393 | < Previous Page | 50 51 52 53 54 55 56 57 58 59 60 61  | Next Page >

  • Something similar to this C# code in Ruby on Rails

    - by Jimmy
    Hey guys, I am trying to get a collection of objects based on a conditions. Now normally in C# I would do something like this employeesCollection.Where(emp => emp.Name == "john"); how can I do something similar in Ruby on Rails (I am trying to map a collection of objects to a select but I only want to map certain objects that match a condition. My current ruby on rails code looks like this <%= select( 'page', 'id', @post.pages.map {|page| [page.title, page.id]}) %> I want to add a condition to an attribute of page Can anyone help?

    Read the article

  • Summarize object area with a Hash in Ruby

    - by Arto Uusikangas
    require 'sketchup' entities = Sketchup.active_model.entities summa = Hash.new for face in entities next unless face.kind_of? Sketchup::Face if (face.material) summa[face.material.display_name] += face.area end end Im trying to get the structure in the array as such: summa { "Bricks" = 500, "Planks" = 4000 } Making a ruby script for Google Sketchup btw But if I run this code i only get Error: #+' for nil:NilClass> C:\Program Files (x86)\Google\Google SketchUp 7\Plugins\test.rb:17 C:\Program Files (x86)\Google\Google SketchUp 7\Plugins\test.rb:14:ineach' C:\Program Files (x86)\Google\Google SketchUp 7\Plugins\test.rb:14 C:\Program Files (x86)\Google\Google SketchUp 7\Plugins\test.rb:8:in `call' As im used to using PHP and just doing $array['myownassoc'] += bignumber; But i guess this isnt the right approach when using Ruby? So any help in how i need to go would be nice.

    Read the article

  • Track unicode words from Twitter using Ruby and the Tweetstream API

    - by Régis B.
    I am trying to track a set of keywords from Twitter by using the Streaming API (can't post the link here because of spam limitations: google twitter streaming API). I am doing this inside Ruby, using the TweetStream gem: http://bit.ly/cODAWI The problem I have is that I want to track keywords that contain some unicode/UTF-8 characters. For instance: require 'rubygems' require 'tweetstream' TweetStream::Client.new("my_user_name", "my_password").track("é") do |s| puts s.text end (you can try it out, provided you installed the tweetstream and json gems) This piece of code does not print anything, while replacing "é" with "e" outputs a bunch of tweets continuously. I did not find any reliable documentation about Unicode in Ruby, so I have no idea where the problem comes from. Thanks for your help!

    Read the article

  • Ruby on Rails, PHP or C++ for web social network

    - by faya
    Hello, I have chosen diploma work in university. It's a mini social network. But now I am really stuck with which technology I should stick. I am average at C++ ISAPI web services development, below average PHP(had few projects with it) and new to Ruby and its framework RAILS. I have a deadline 1.5 month to develop it(about 5 hours every day after my full time job). Also I heard that its very easy to learn and develop with Ruby on Rails. Considering C++ I know that I have to do lots of coding and work by myself and PHP looks almost the same to me. So I am looking for you skilled developers advise what would you do in my position? Learn RoR, stick with C++ or PHP or maybe use something else?

    Read the article

  • Ruby TCPSocket doesn't notice it when server is killed

    - by user303308
    I've this ruby code that connects to a TCP server (namely, netcat). It loops 20 times, and sends "ABCD ". If I kill netcat, it takes TWO iterations of the loop for an exception to be triggered. On the first loop after netcat is killed, no exception is triggered, and "send" reports that 5 bytes have been correctly written... Which in the end is not true, since of course the server never received them. Is there a way to work around this issue ? Right now I'm losing data : since I think it's been correctly transfered, I'm not replaying it. #!/usr/bin/env ruby require 'rubygems' require 'socket' sock = TCPSocket.new('192.168.0.10', 5443) sock.sync = true 20.times do sleep 2 begin count = sock.write("ABCD ") puts "Wrote #{count} bytes" rescue Exception => myException puts "Exception rescued : #{myException}" end end

    Read the article

  • What comes first in Ruby's object model?

    - by Timothy
    I've been reading Metaprogramming Ruby and the object model like the chicken or egg dilemma. In Ruby 1.8, the Object class is an instance of Class. Module's superclass is Object and is an instance of Class. Class' superclass is Module, and it is an instance of Class (self-referential). Say class SomeClass; end is defined somewhere; SomeClass is an instance of Class, however its superclass is Object. Why does an instance of Class have Object as the superclass instead of nil? Also, if Object is to exist, then Class has to exist, but then Module has to exist, but for Module to exist Object has to exist. How are these classes created?

    Read the article

  • Convert the code from PHP to Ruby on rails

    - by theband
    public function getFtime() { $records=array(); $sql="SELECT * FROM `finishedtime`"; $result=mysql_query($sql); if(!$result){throw new Exception(mysql_error());} if(mysql_num_rows($result)==0){return $records;} while($row=mysql_fetch_assoc($result)){$records[]=$row;} return $records; } I am in the process of learning Ruby, can anyone convert this code into Ruby. This will make me construe on how to run a query and thrown the fetched result back.

    Read the article

  • learning and "singing" Ruby with Sinatra

    - by microspino
    Hello I'm trying to improve my ruby knowledge by reading The Ruby Programming Language book. Reading Coders at work I saw that lot of the interviewees suggest to dive into a project source code to learn best practices to be aware of bad habits and of course to take new inspirations for how to do things. I decided to pick a project as more self contained as I could find. My choice was Sinatra since It's 1000 LOC. Is It a good project to learn? Do you suggest another one more simple (i.e. less LOCs)? I've tried to see rails machinery before but I came out scared from It.

    Read the article

  • Up to date Ruby On Rails books?

    - by Earlz
    Hello, I've been trying to learn Rails for a while now and I just can not piece it all together with random blogs and SO questions, so I've decided I need a full book/ebook. Can anyone suggest a good one? I've been looking at Agile Web Development With Rails 4th edition. There is an old question about Ruby On Rails books but it is from 2008 and there has been new Rails releases since then. I basically would like a book that is more than a reference, but also doesn't assume I'm a non-programmer. Also, I already know a lot of Ruby. So, what books would you recommend that is up to date and also doesn't treat me like a baby?

    Read the article

  • Is the ruby operator ||= intelligent?

    - by brad
    I have a question regarding the ||= statement in ruby and this is of particular interest to me as I'm using it to write to memcache. What I'm wondering is, does ||= check the receiver first to see if it's set before calling that setter, or is it literally an alias to x = x || y This wouldn't really matter in the case of a normal variable but using something like: CACHE[:some_key] ||= "Some String" could possibly do a memcache write which is more expensive than a simple variable set. I couldn't find anything about ||= in the ruby api oddly enough so I haven't been able to answer this myself. Of course I know that: CACHE[:some_key] = "Some String" if CACHE[:some_key].nil? would achieve this, I'm just looking for the most terse syntax.

    Read the article

  • ruby rails installation problem

    - by CHID
    Hi i am installing ruby on rails. I installed version 3.0.0 and then wanted to update it to version 3.0.1 So i removed the executable files by giving gem uninstall rails Then i again tried installing by giving gem install rails -v 3.0.1 It says Succesfully installed rails-3.0.1 1 gem installed Installing ri documentaion details for rails -3.0.1 File not found: lib I tested by giving rails -v Now it is saying an error called Could not find gem 'sqlite3-ruby (= 0, runtime)' in any of the gem sources list ed in your Gemfile. Try running `bundle install`. Can anyone tell me what i am missing. I am using WINDOWS 7

    Read the article

  • Ruby string encoding problem

    - by John Prideaux
    I've looked at the other ruby/encoding related posts but haven't been able to figure out why the following is not working. Likely just because I'm dense, but here's the situation. Using Ruby 1.9 on windows. I have a set of CSV files that need some data appended to the end of each line. Whenever I run my script, the appended characters are gibberish. The input text appears to be IBM437 encoding, whereas my string I'm appending starts as US-ASCII. Nothing I've tried with respect to forcing encoding on the input strings or the append string seems to change the resultant output. I'm stumped. The current encoding version is simply the last that I tried. def append_salesperson(txt, salesperson) if txt.length > 2 return txt.chomp.force_encoding('US-ASCII') + %(, "", "", "#{salesperson}") end end salespeople = Hash[ "fname", "Record Manager"] outfile = File.open("ActData.csv", "w:US-ASCII") salespeople.each do | filename, recordManager | infile = File.open("#{filename}.txt") infile.each do |line| outfile.puts append_salesperson(line, recordManager) end infile.close end outfile.close

    Read the article

  • Ruby-Graphwiz does not render png

    - by auralbee
    I just tried the ruby-graphwiz gem (http://github.com/glejeune/Ruby-Graphviz). I followed the instructions (installed Graphwiz, gem and dependencies) and tried the example from the Github page. Unfortunately I am not able to render any output image (png,dot). # Create a new graph g = GraphViz.new( :G, :type => :digraph ) # Create two nodes hello = g.add_node( "Hello" ) world = g.add_node( "World" ) # Create an edge between the two nodes g.add_edge( hello, world ) # Generate output image g.output( :png => "hello_world.png" ) When I run the skript from the console I get no error message but also no output as expected. What could be the problem? Folders have read/write access for everybody. Thanks in advance. By the way, I´m working on a Mac (Leopard 10.6).

    Read the article

  • Running python/ruby script on iPhone?

    - by prosseek
    From the recent news from the Apple, I learned that one has to use C/C++/Objective-C for iPhone App. Accordingly, it's not possible to use MacPython or similar to make iPhone App. But as the python/ruby interpreter itself is written in C, isn't it OK to make python/ruby interpreter for iPhone to run the scripts on iphone? Is this possible? Does Apple support this? Or does someone implemented this? Or, the user should hack to do this?

    Read the article

  • Best practices with STDIN in Ruby?

    - by griflet
    I want to deal with the command line input in Ruby: > cat input.txt | myprog.rb > myprog.rb < input.txt > myprog.rb arg1 arg2 arg3 ... What is the best way to do it? In particular I want to deal with blank STDIN, and I hope for an elegant solution. #!/usr/bin/env ruby STDIN.read.split("\n").each do |a| puts a end ARGV.each do |b| puts b end

    Read the article

  • how to controller (start/kill) a background process (server app) in ruby

    - by rubiii
    hey guys, i'm trying to set up a server for integration tests (specs actually) via ruby and can't figure out how to control the process. so, what i'm trying to do is: run a rake task for my gem that executes the integration specs the task needs to first start a server (i use webrick) and then run the specs after executing the specs it should kill the webrick so i'm not left with some unused background process webrick is not a requirement, but it's included in the ruby standard library so being able to use it would be great. hope anyone is able to help! ps. i'm running on linux, so having this work for windows is not my main priority (right now).

    Read the article

< Previous Page | 50 51 52 53 54 55 56 57 58 59 60 61  | Next Page >