The helper method current_user is defined and made available as a helper in ApplicationController like this:
class ApplicationController < ActionController::Base
helper_method :current_user
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session....
Hi,
Just wondering if anyone has any realworld examples or know when you might use the NOT, AND, OR, XOR, <<, >> operators in Ruby.
I've been programming for 4 years and never come across the need to use any of these, wondering how common actual usage is & if its something I should fully understand.
Thanks,
-J
...
I have a table that is 26 squares by 26 squares. Each square is going to be 30px * 30px.
Given the tiles
upper_left.png
upper_right.png
upper_wall.png
and:
left_wall.png
right_wall.png
and:
bottom_left.png
bottom_wall.png
bottom_right.png
I aim to comprise a background that is 780px*780px.
For the sake of speed and to preven...
What I want to do is automatically post to facebook when a user post something on his profile (inside my app), I want to remember the user facebook credential to post automatically without asking for his credentials again.
Tumblr has already implement this functionality and I want to emulate it.
What is the best way to implement this f...
print (-1 == -1) and (myobj.nil?)
true
print (-1 == -1) && (myobj.nil?)
false
Note, myobj.nil? returns false
so, should not this always be false.
...
Hi,
I am familiar with the concept of nesting classes and modules within another module and grouping them in a namespace. What is the idea / purpose behind
Nesting classes within another class
class A
class B
def method_B
...
end
end
end
2.Nesting modules within another class
class A
module c
def...
I am testing an iframe within a page. When I run my ruby script with selenium-rc, the page loads up fine but the iframe goes into an infinite loading causing my script to time-out. Though on manually checking the same script, we get the expected result.
Any idea if selenium does something with the browser settings?? I have tried it with ...
I have the following program.
module C
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def test_for
class_eval <<-DEFINECLASSMETHODS
def self.my_method(param_a)
puts "SELF is: #{self.inspect}"
puts param_a
puts "#{param_a}"
end
DEFINECLAS...
I am using ruby 1.8.7. I am not using rails.
How do I find all the links which are not already in anchor tag.
s = %Q{ <a href='www.a.com'><b>www.a.com</b></a> www.b.com <div>www.c.com</div> }
The output of above string should be
www.b.com
www.c.com
I know "b" tag before www.a.com complicates the case but that's what I have to wor...
How to easily change the format of URL in a right way:
/comment/10.js?param1=6
to
/comment/10?param1=6
Preferrably with some URL library or so, not with regexps.
Use case: redirect back with request.request_uri saved in session.
...
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
b...
I am working on a web application where I have to encode and decode a string at the JavaScript side and Ruby backend of the code. the only problem is that the escape methods for JavaScript and Ruby have a small difference. in JavaScript the " " is treated as "%20" but in ruby the " " is encoded to "+".
Any way to solve this? Another Rub...
I need to play, pause and resume AAC (audio) files from a ruby console program (much like iTunes or any music player).
After much searching, I've come across these libraries:
mp3info
metadata
id3lib-ruby
rvideo (uses ffmpeg)
These seem to help me in getting track length and tags which i also need, but I need something to p...
I am using the code:
<%= image_tag site.photo.url(:small) if site.photo.file? %>
to tell my app to display nothing if there is no photo associated with a particular post (site in this case). Is there a way to render a message along w/ this. For instance "no image with the post". I tried simply doing
<%= if site.photo.file? %>
<p> n...
I have the following (snipped) parameters passed into my controller.
Parameters: {"commit"=>"OK", "action"=>"set_incident_incident_status_id", "id"=>"1", "controller"=>"incidents", "incident"=>{"incident_status_id"=>"1"}}
I know that if I want to select the incident, I can do:
@incident = Incident.find(params[:id])
How do I access ...
I am trying to execute a powershell script from Ruby, I have entered the below command:
scriptPath = system('powershell \"C:\\Scripts\\DB_Setup.ps1\"')
The ruby Script is handling exceptions when an error is raised to stop the script as below command:
rescue => ex
message = "\nscript on server '#{`hostname`.strip()}' terminated u...
I want to automate this scenario. UserA assign an item to UserB, who gets an alert message. In order to do this I want to have two different browsers launched with different accounts to test this interaction. Is is possible to do this? If yes, how?
...
I am using ruby 1.8.7.
p = lambda { return 10;}
def lab(block)
puts 'before'
puts block.call
puts 'after'
end
lab p
Above code output is
before
10
after
I refactored same code into this
def lab(&block)
puts 'before'
puts block.call
puts 'after'
end
lab { return 10; }
Now I am getting LocalJumpError: unexpected return...
I have a date range that I would like to be able to loop through in reverse. Give the following, how would I accomplish this, the standard Range operator doesn't seem t be working properly.
>> sd = Date.parse('2010-03-01')
=> Mon, 01 Mar 2010
>> ed = Date.parse('2010-03-05')
=> Fri, 05 Mar 2010
>> (sd..ed).to_a
=> [Mon, 01 Mar 2010, Tu...
I need to "blindly" (i.e. without access to the filesystem, in this case the source control server) convert some relative paths to absolute paths. So I'm playing with dotdots and indices. For those that are curious I have a log file produced by someone else's tool that sometimes outputs relative paths, and for performance reasons I don't...