Hello All,
I am trying to get hold of rails counter cache feature but not able to grasp it completely.
Let's say that We have 3 models
A B C
A belongs to B or C depending upon a field key_type and key_id. key_type tells whether A belongs to B or C so if key_type="B" then the record belongs to B otherwise it belongs to C.
In my mode...
Hello guys,
I'm using sinatra/frankie/facebooker to prototype something simple to test the facebook api, i'm using mmangino-facebooker the more recent version from github and I cloned the most recent version of frankie. I'm using sinatra 0.9.6.
My main code is as simple as possible:
before do
ensure_application_is_installed_by_faceb...
"select * from users, awards where (users.id = awards.user_id) and awards.trophy_id not in (select awards.trophy_id from awards where awards.trophy_id = #{trophy.id})"
...
I am using the really awesome ruby ffi library to access functions in a c library in ruby.
Is there a way to iterate over the layout of a Ruby FFI::Struct?
example FFI::Struct:
class Example < FFI::Struct
layout :name, string,
:desc, :string,
:type, :int,
:value, :string
end
this doesn't seem to work but...
I have a Ruby method that searches an array of hashes and returns a subset of that array.
def last_actions(type = 'all')
actions = @actions
if type == 'run'
actions = actions.select {|a| a['type'] == "run" }
end
return actions
end
This works, except when there is only one action to return, in which case I ...
So I am trying to get the cancan gem to work with my rails 3 app and I've hit a problem.
I tried to copy the code that Ryan Bates (the creator of the gem) used in his screen cast, but I get an error saying that roles_mask is not a method. I figure that the _mask method was removed from Ruby/Rails at some point, and I'm now wondering wh...
hi
I know about the built-in I18n in Rails, but how can I select a database field per locale?
My model structure is something like this:
title #default (englisch)
title_de #(german)
title_it #(italian)
In my template I want to be able to write only
<%= @model.title %>
and should get the value in the right language.
Is there ...
So I have the following hashes/arrays:
{"number"=>[{"tracking"=>"1Z81E74W0393736553", "notes"=>"Example note"}, {"tracking"=>"9102901001301227214058"}]}
{"number"=>{"tracking"=>"1Z81E74W0393736553", "notes"=>"Example note"}}
That first hash has an array for number while the second one doesn't.
It's wreaking havoc trying to loop thro...
I'm playing around with MongoMapper but I'm having trouble figuring out how to create a form for an object that has embedded documents.
With ActiveRecord, I'd use fields_for but when asked if this would be supported a few months ago, MongoMapper author John Nunemaker wrote: "Nope and nope. It is really [not] that hard with attr_accessor...
I'm building out a medium-sized application using Sinatra and all was well when I had a single app.rb file and I followed Aslak's guidance up on Github:
http://wiki.github.com/aslakhellesoy/cucumber/sinatra
As the app grew a bit larger and the app.rb file started to bulge, I refactored out a lot of of the bits into "middleware" style m...
I'm now learning Ruby because I saw it's a very powerfull language, but now I want to know what mobile ports of Ruby we have and for what devices.
PS: I have a HTC S711, HP iPAQ Hx2, Nokia E61, Nokia N95, Palm T|X, Palm Z22, HP Jornada 720..., it's better if I can use it on these platforms, but I'm open to buy other devices, as I'm a mo...
What's the simplest way of changing a negative number to positive with ruby?
ie. Change "-300" to "300"
...
I'm trying to use ruby-debug to debug this script I've written and it keeps terminating on the line, if __FILE__ == $0. I step through each line before it, and then when it gets to that line it just quits. No errors or anything, it just quits. How do I fix this?
...
I am trying to install sqlite3 and sqlite-ruby (ruby 1.8.6) on a linux box where I do not have root.
I downloaded the sqlite3 source, binaries, and shared library and placed them all in a directory called sqlite3
I then try to install sqlite-ruby using
gem install sqlite-ruby --with-sqlite-dir=the_path_sqlite/sqlite3
but I keep getti...
Hi, trying to get my head around Feedzirra here.
I have it all setup and everything, and can even get results and updates, but something odd is going on.
I came up with the following code:
def initialize(feed_url)
@feed_url = feed_url
@rssObject = Feedzirra::Feed.fetch_and_parse(@feed_url)
end
def update_from_feed_cont...
Hi All,
I'm looking for some tutorials/resources/tips that will show me how to run applications via a ruby script. I have several small tools that we use in our day to day operations that I want to manage their tasks in one ruby script.
Basically what I'm trying to do is:
run app via ruby script.
(wait for result) get result code ...
So I'm building a rails app for high school students and I've hit a problem when it comes to creating users.
I want the students to only be able to create accounts if they select their school and type in their school's password correctly.
What is the correct / easiest way of doing this? Should I create a gatekeeper to the user#new acti...
I'm working on a module that, among other things, will add some generic 'finder' type functionality to the class you mix it into. The problem: for reasons of convenience and aesthetics, I want to include some functionality outside the class, in the same scope as the class itself.
For example:
class User
include MyMagicMixin
end
# S...
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 hi...
Hi,
I need to extract the actual phone number form the html listed below, but I'm not really sure how to do it using Nokogiri CSS since there are no html tags around it. When an at_css(.phonetitle) it only parse Phone and not the number.
<div class="detail">
<span class="address">Corner of Toorak Road and Chapel Street, South Yarra...