Search Results

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

Page 15/393 | < Previous Page | 11 12 13 14 15 16 17 18 19 20 21 22  | Next Page >

  • Stop duplicates from being added to an array of Ruby objects

    - by Dom
    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

    Read the article

  • numerical computation locks up ruby

    - by kolosy
    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?

    Read the article

  • Login to a Remote Service (ruby based) from iPhone

    - by Chris Maness
    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.

    Read the article

  • Support for IMAP IDLE in ruby

    - by Asaxena
    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.

    Read the article

  • Compare two times without regard to Date associated - Ruby

    - by H55nick
    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?

    Read the article

  • How do I print an array in Rails?

    - by Abid Hussain
    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?

    Read the article

  • Routing Users to single Models with Rails

    - by Eric Koslow
    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!

    Read the article

  • Headless gem: webkit_server: cannot connect to X server

    - by 23tux
    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?

    Read the article

  • Rails 3.0/3.2: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

    - by Nick5a1
    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?

    Read the article

  • Build custom error messages in model files (example: using the 'pluralize' method)

    - by user502052
    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?

    Read the article

  • Rendering another Action without changing URL?

    - by Michael Stum
    I have this code in my Rails 3 controller: def index now = Time.now.utc.strftime("%m%d") redirect_to :action => "show", :id => now end def show begin @date = Time.parse("12#{params[:id]}") dbdate = params[:id] rescue ArgumentError @date = Time.now.utc dbdate = @date.strftime("%m%d") end @date = @date.strftime("%B %d") @events = Event.events_for_date(dbdate) end So basically index is just a specialized version of show, hence I want it to execute show, render the show.html.erb view - but I do not want to change the URL like redirect_to does. I have tried this approach: def index now = Time.now.utc.strftime("%m%d") params[:id] = now show render :action => "show" end Now, this works, but it just smells badly. I'm new to Ruby and Rails, so I just wonder if there is something fundamentally wrong or if there is a better way to do this?

    Read the article

  • Rake migration aborted

    - by user2537714
    I'm running Ruby 2.0.0 and I installed it correctly. Just loaded up a gem 'devise' and as I tried to migrate my database changes, it wouldn't work: $ rake db:migrate rake aborted! attr_accessible is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add protected_attributes to your Gemfile to use old one. Then, following another Stackoverflow post, they recommended installing Bundler. I did that successfully and got this: $ bundle exec rake db:migrate rake aborted! attr_accessible is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add protected_attributes to your Gemfile to use old one. Is anyone up to the challenge to help?

    Read the article

  • What is a valid and reasonable alternative to a massive storage approach?

    - by Backo
    I am using Ruby on Rails 3.2.2 and MySQL. After my previous question on "how to handle massive storage of records in database for user authorization purposes", since related answers (on how to solve the issue or how to accomplish to that I am looking for) aren't sufficiently detailed or require to much resources (at least for me), I would like to know what are valid and reasonable alternatives to that approach. In few words, this question could be phrase as: how to handle "complex" (at level of SQL querying) user authorizations when you have to fetch "authorized" records? That is, for example, how to retrieve records when you would use code like the following (the following code would be used mostly in index controller actions): Article.readable_by_user(@current_user) # => Returns all articles readable by the current user.

    Read the article

  • Compiling Ruby on Mac OS X Snow Leopard

    - by gryzzly
    Hi, I am trying to follow this tutorial, on the subject of compiling ruby and rubygems on Snow Leopard: http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard I have added this to my ~/.profile: export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH" But if I write: echo $PATH I get: /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin But in tutorial it says: You should see /usr/local/bin at the beginning of the line returned by the system. I have installed macports sometime ago and plenty of other software, perhaps it has changed the path. Anyway, I have tried to proceed with the installation, so I have built ruby, I did: ./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1 make sudo make install cd .. But when I do which ruby I get: /usr/bin/ruby And according to the tutorial that's wrong. Also if I do ruby -v I get the older version of ruby that was preinstalled on Snow Leopard and not the one I've compiled. Thanks.

    Read the article

  • Ruby on Rails has_one Model Not Supplying ID Column

    - by Metric Scantlings
    I have a legacy rails (version 1.2.3) app which runs without issue on a number of servers (not to mention my local environment). Deployed to its newest server, though, and I now get ActiveRecord::StatementInvalid: Mysql::Error: #23000Column 'video_id' cannot be null errors. Below are the models/relationships, simplified: class Video < ActiveRecord::Base has_one(:user, :dependent => :destroy) end class User < ActiveRecord::Base belongs_to(:video) end And below is a rails console transcript of the relationships failing: >> video = Video.create(:title => 'New Video') => #<Video:0xb6d5e31c>... >> video.id => 5 >> video.user = User.create(:name => 'Tester') ActiveRecord::StatementInvalid: Mysql::Error: #23000Column 'video_id' cannot be null: INSERT INTO users (`name`, `video_id`) VALUES('Tester', NULL) from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract_adapter.rb:128:in `log' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:243:in `execute' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:253:in `insert' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1811:in `create_without_callbacks' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:254:in `create_without_timestamps' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/timestamp.rb:39:in `create' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1789:in `create_or_update_without_callbacks' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:242:in `create_or_update' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1545:in `save_without_validation' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:752:in `save_without_transactions' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:451:in `create' from (irb):3 from :0 Has anyone else come across ActiveRecord not sending an ID when it clearly knows it?

    Read the article

  • Is it possible for beginner to learn and develop an application in rails in 4 months?

    - by Parth
    I want to develop a web application or a website using rails. My current knowledge includes 1. HTML 2. CSS 3. C 4. Java And I am currently going through 5th chapter of the well grounded rubyist book by David A. Thomas. I came to know that learning ruby is beneficial for good knowledge of rails. So currently I am going through the basics of ruby. And learning rails in parallel. I want to know if in this scenario is it practically feasible to understand rails and develop an application/website in it within the time frame of 4 months. I need to develop an application which have atleast 3 complexity (complex functionality). Any ideas of good application for rails beginners is welcomed. But the application should be large or if it is small than it should have some complexity. Time is a constraint for me. I would have to develop application for college work but rails technology is my choice as I want to learn it.

    Read the article

  • Installing and using acts-as-taggable-on

    - by seaneshbaugh
    This is going to be a really dumb question, I just know it, but I'm going to ask anyways because it's driving me crazy. How do I get acts-as-taggable-on to work? I installed it as a gem with gem install acts-as-taggable-on because I can't ever seem to get installing plugins to work, but that's a whole other batch of questions that are all probably really dumb. Anyways, no problems there, it installed correctly. I did ruby script/generate acts_as_taggable_on_migration and rake db:migrate, again no problems. I added acts_as_taggable to the model I want to use tags with, started up the server and then loaded the index for the model just to see if what I've got so far is working and got the following error: undefined local variable or method `acts_as_taggable' for #. I figure that just means I need to do something like require 'acts-as-taggable-on' to my model's file because that's typically what's necessary for gems. So I did that hit refresh and got uninitialized constant ActiveRecord::VERSION. I'm not even going to pretend to begin to know what that means went wrong. Did I go wrong somewhere or there something else I need to do. The installation instructions seem to me like they just assume you generally know what you're doing and don't even begin to explain what to do when things go wrong.

    Read the article

  • Database not completely updated in rails migration

    - by Aatish Sai
    I am new to Ruby on Rails. I have a migration called create user class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.column :username, :string, :limit => 25, :default => "", :null => false t.column :hashed_password, :string, :limit => 40, :default => "", :null => false t.column :first_name, :string, :limit => 25, :default => "", :null => false t.column :last_name, :string, :limit => 40, :default => "", :null => false t.column :email, :string, :limit => 50, :default => "", :null => false t.column :display_name, :string, :limit => 25, :default => "", :null => false t.column :user_level, :integer, :limit => 3, :default => 0, :null => false end User.create(:username=>'test',:hashed_password=>'test',:first_name=>'test',:last_name=>'test',:email=>'[email protected]',:display_name=> 'test',:user_level=>9) end end When I run rake db:migrate the table is created with the columns as mentioned above but the test data are not there mysql>select * from users; Empty set (0.00 sec) EDIT I just dropped the whole database and restarted the migration and now it is showing the following error. rake aborted! An error has occurred, all later migrations canceled: Can't mass-assign protected attributes: username, hashed_password, first_name, last_name, email, display_name, user_level What am I doing wrong please help? Thank you.

    Read the article

  • [BUG] gc_sweep() with ruby 1.8.7

    - by kgrad
    I have a rails app being developed with mongrel 1.1.5. I can run the app and click on 3 or 4 links, but after that mongrel always crashes with an error: [BUG] gc_sweep(): unknown data type 0x0. It happens on both windows 7 and mac os x snow leopard, so it has to be something in my code, or something wrong with ruby 1.8.7 (less likely). Has anyone else experienced this? Is there a fix or likely cause? thanks edit: interestingly, it does not crash when deployed via heroku.

    Read the article

  • Ruby/Rails display general screen when modifications being performed on server

    - by john chan
    I have a ruby on rails app running a server and sometimes it needs to be taken down for updates/etc. As of now, one way I see to have a general display screen during update periods (when the app is down) is to substitute the files within /srv/www/ directory to just have it display a general screen everywhere that the user could possibly navigate to. I also thought of having a central controller file that connects all others (essentially a main) but this seems counter intuitive for rails. There are many external links to these different components of the site that the user could navigate to from outside and I need to make sure that they always receive this general update screen when the app is taken down for a little. I was wondering if anyone had any other ideas.... maybe a library or something like that, I can't seem to find anything online. any suggestions would be appreciated. Thanks

    Read the article

  • PostgreSQL / Ruby for commercial application

    - by RPK
    I am planning a web-based commercial application with front-end RoR and back-end PostgreSQL. I've some confusion about RoR and PostgreSQL Edition to use. For RoR, I have Aptana RADRails installed. For PostgreSQL, a free variant is also available at EnterpriseDB. Previously I installed a free EnterpriseDB PostgreSQL variant and it was very smooth and had professional touch. It was quite different from the one available from PostgreSQL website. I want to know which IDE and RoR variant to use for my project. I have no idea of Ruby and Rails. I will be learning and developing simultaneously. Also, which PostgreSQL variant to use? Can these two technologies be used for a developing a commercial application?

    Read the article

  • Automated testing with Ruby on Rails - best practices

    - by randombits
    Curious, what are you folks doing in as far as automating your unit tests with ruby on rails? Do you create a script that run a rake job in cron and have it mail you results? a pre-commit hook in git? just manual invokation? I understand tests completely, but wondering what are best practices to catch errors before they happen. Let's take for granted that the tests themselves are flawless and work as they should. What's the next step to make sure they reach you with the potentially detrimental results at the right time?

    Read the article

< Previous Page | 11 12 13 14 15 16 17 18 19 20 21 22  | Next Page >