For example:
class UsersController < ApplicationController
def doSomething
end
def doSomethingAgain
end
end
Can I restrict the user pass a get method only to doSomething, but doSomethingAgain is only accept post method, can I do so?
...
I had to convert a series of sentences into camel-cased method names. I ended writing something for it. I am still curious if there's something simpler for it.
Given the string a = "This is a test." output thisIsATest
I used for following:
a.downcase.gsub(/\s\w/){|b| b[-1,1].upcase }
...
Can't i do it like this:
class Hardware
before_filter
def before_filter
puts "ge"
end
end
It says before_filter is undefined method or variable when I instantiate it
hd = Hardware.new
because ive seen others put a method name in a class before. Just wondering how it works. Thanks
...
I have the following (heavily simplified) model, that uses will_paginate
class Search < ActiveRecord::Base
attr_reader :articles
def after_initialize
@articles = Article.paginate_by_name name, :page => 1
end
end
and the controller code in my show action is
@search = Search.new(params[:search])
This all works fine, but ...
I am trying to run metric_fu on a Rails 3 application. All is good, with the exception of rcov. I have RSpec configured and my tests follow the spec/*/.rb format and run fine in RSpec. Trying to check coverage with rcov, however, I get the following errors:
** Running the specs/tests in the [test] environment
No file to analyze was ...
i want to do
current_user.allow_????? = true
where ????? could be whatever I wanted it to be
I've seen it done before.. just don't remember where, or what the thing is called.
...
I want to do
current_user.field = User::?????????
Where ?????????? would be whatever I wanted it to be
This what I'm trying to do
Given /^"([^\"]*)" is a(?:|n) "([^\"]*)"$/ do |arg1, arg2|
cur_user = User.find(:first, :conditions => ['name = ?', arg1])
cur_user.update_attributes(:role => User::arg2.constantize)
end
While const...
Hi,
I'm trying to write a ruby class that works similarly to rails activerecord model in the way that attributes are handled:
class Person
attr_accessor :name, :age
# init with Person.new(:name => 'John', :age => 30)
def initialize(attributes={})
attributes.each { |key, val| send("#{key}=", val) if respond_to?("#{key}=") }
...
Hi,
I was doing the following on the terminal:
script/server
it says the server host:3000 was being used,
when I typed it into web browser, the page loads but when I click on my environment the info doesn't show up. I get an error message
if I change the server by typing in
script/server -p 3001
for example, it works,
so my qu...
Hi,
I am using Amazon S3 service to upload different directories (and the files inside) to different buckets (directory -> bucket).
I am coding in Ruby, and I am using the lib http://amazon.rubyforge.org.
The files are small (about 20KB).
I'd like to upload the directories in parallel (using many threads) but I have to use synchronize ...
I know how to loop a combo box by using this:
<%= f.collection_select(:category_id , Category.all, :id, :name, {:prompt => false})%>
and now, I can do radio box using the radio box help:
radio_button("user", "receive_newsletter", "yes")
But how can I do this in a form helper? thank you.
...
Hey guys. I'm able to send Rails consoles to the background with CTRL+Z . However, when I bring back the console with "fg", the console's no longer responsive.
It doesn't respond to normal commands, or even "quit" or CTRL+C. I have to background it again with CTRL+Z , and then kill it with "kill %1".
Here's an example:
[nickh@chameleo...
Hi guys,
I have a problem - I don't know the amount of data being sent to my UDP server.
The current code is this - testing in irb:
require 'sockets'
sock = UDPSocket.new
sock.bind('0.0.0.0',41588)
sock.read # Returns nothing
sock.recvfrom(1024) # Requires length of data to be read - I don't know this
I could set recvfrom to 65535 ...
So I'm writing some rspec tests and I'm embarrassed at my lack of Ruby understanding.
I have a file structure that looks like the following:
GUI_Tests/Tests/test_spec.rb
GUI_Tests/windows_gui.rb
GUI_Tests/upload_tool.rb
when I run spec for the test_spec.rb file, I require the upload_tool file to be included like so:
spec -r ../...
require 'rubygems'
require 'test/unit'
class Thing
attr_accessor :foo
def set_stuff
@foo = 'bar'
end
end
class ThingTest < Test::Unit::TestCase
def setup
@thing = Thing.new
end
def test_set_stuff
@thing.set_stuff
assert 'bar' == @thing.foo
end
def test_foo_in_other_test
puts @thing.foo
assert ...
Can anyone tell me how I can get a list of the available disk drives in ruby? I am creating an open file dialogue and need to know! Thanks in advance, ell.
...
At the moment, I am doing my complex queries by hand so to speak. But I keep encountering problems. For instance.
query = "SELECT histories.candidate_id
FROM histories
WHERE histories.institution_id IN (?)
GROUP BY histories.candidate_id
HAVING COUNT(*)= ?"
cand = [Code.fi...
Has anyone here ever encountered the following error after installing and attempting to run the Geocommons geocoder on Mac OS X 10.5.8? This is my exact output from the Terminal window from the point at which I started irb:
$ irb
>> require 'geocoder/us'
=> true
>> db = Geocoder::US::Database.new("/opt/tiger/orangeca.db")
=> #<Geocoder...
Hello!
I have an existing mysql db used by a rails app. I want to create a Ruby script to run to perform a weekly maintenance task on the database. My first line is:
require 'mysql'
I have tried various 'paths' to point there but get an error message like:
1:in `require': no such file to load
I have:
code at: \ruby\sites\som...
I need to update a model after delayed_job processes a task on it, e.g:
foo.delay.something
After something is done, I need to update the foo object, what is the best way to achieve this? I was thinking in coding a callback on the Delayed::Backend::ActiveRecord::Job class, but there's should be something cleaner and better to do this. ...