Here is the code generated by rails:
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
format.html { redirect_to(@user) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
...
Assume that I have a global variable user in application....like this:
# GET /users.xml
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
end
Is that mean every request, a new @user is created? If every request , an object is cre...
I'm trying to do some scripted GUI testing in Windows using Ruby. I'm leveraging the guidance of a pragprog book and I'm hitting a bit of a snag. I've factored out some code to help with the repeatitive mapping of win32api functions. The code is as follows:
module WindowsGui
def self.def_api(function, parameters, return_value) ...
Hi, I've just installed "sequel" gem for Ruby. I wanted to try example from Sequel website and it won't work :(
test.rb:
require 'rubygems'
require 'sequel'
DB = Sequel.sqlite # memory database
DB.create_table :items do
primary_key :id
String :name
Float :price
end
items = DB[:items] # Create a dataset
# Populate the tab...
HI
how can i ensure that a string contains no digits using regex in ruby?
thanks
...
I noticed a problem with indexing my rails app when submitting it to Google webmaster tools and testing with curl.
My root is currently set like so:
map.root :controller => "posts"
which will explain when i run:
$ curl http://0.0.0.0:3000
it only returns the posts controller and not the homepage in its entirety:
<div class="post"...
I'm trying to display some git version information (via grit) in my rails application footer for debuging. When I want to see the head, it's straightforward:
@git_repository = Grit::Repo.new( Ter::Application.root )
head = @git_repository.heads.first
t '.git_info', :revision => head.commit.id, :branch => head.name, :author => head.commi...
Hi, in ruby
I still can't figure out how to make a subclass constructor follow its parent...
example:
require 'mechanize'
class Scraper
attr_accessor :agent
def initialize
# I dont know if using instance variable is the right thing to do
@agent = Mechanize.new
end
end
class ScraperA < Scraper
end
I want to m...
How do I override methods in a module?
...
The previous question is here :
http://stackoverflow.com/questions/3229758/what-is-the-common-practice-on-limit-the-result-in-ror
Here's the users_controller:
def show
@user = User.find(params[:id])
@posts = @user.posts.paginate :page => params[:page]
respond_to do |format|
format.html # show.html.erb
format.xml { re...
So I'm trying to get thin to run as a service with RVM. After a thin install I manually updated /etc/init.d/thin to use an su - user when running the config command so that thin was running as a local user, rather than root. So far so good.
Now, when I try to sudo service thin start it looks like it's trying to use the non-RVM version o...
I am trying to validate that my form fields all have an associated label using Selenium, but I am having problems grabbing all of the form fields on a page. get_all_fields only gets textfields; I have no way to also grab the passwords, radios, checkboxes, etc.
I was trying something like this:
num_fields = Integer(selenium.get_xpath_c...
Inside the Rails code, people tend to use the Enumerable#inject method to create hashes, like this:
somme_enum.inject({}) do |hash, element|
hash[element.foo] = element.bar
hash
end
While this appears to have become a common idiom, does anyone see an advantage over the "naive" version, which would go like:
hash = {}
some_enum.ea...
like a float:
if i == 2.0 i want to get: 2
if i == 2.3 or 2.23 i want to get: 2.3 or 2.23
thanks
...
I like judicious use of the ternary, conditional operator. To my mind it's quite succinct.
However, in ruby, I find I'm often testing predicate methods, which already have their own question marks:
some_method( x.predicate? ? foo : bar )
I'm jarred by those two question marks so close to each other. Is there an equivalently compact...
I'm messing around in Ruby some more. I have a file containing a class with two methods and the following code:
if __FILE__ == $0
seq = NumericSequence.new
puts "\n1. Fibonacci Sequence"
puts "\n2. Pascal\'s Triangle"
puts "\nEnter your selection: "
choice = gets
puts "\nExcellent choice."
choice = case
when 1
put...
I am using the Rails helper datetime_select in one of my forms. I currently have a requirement to change the dropdowns for day, year, hour, and minute to be textboxes with validation. Is there a way I can specify that I want textboxes for these fields? Or possibly a different helper that will do what I need?
here is my usage:
datet...
If I have a remote SFTP server with a folder full of files on it that I want to operate on with Ruby's Dir and File classes, is there a way to do that through the net/ssh and net/sftp libraries?
I know that net/sftp has a few Dir and File utilities strapped to it, but unfortunately they're not the ones I need. I need
File.ctime(my_file...
Newb question of the day:
I'm trying to select all the users with this condition, and then perform an action with each one :
User.find(:all).select { |u| u.organizations.count > 0} do |user|
Except, this isn't the right way to do this. Not entirely sure what the proper syntax is.
Any fellow rubyist offer a newb a hand?
...
Hi,
I'm new to ruby and am having trouble getting a simple watir script to work with IE on ruby v1.9.1. I can get it to work with ruby v1.8.6
Has anyone managed to use watir with Ruby v1.9.1 ?
This is the script i'm using
require 'watir'
browser = Watir::Browser.new
browser.goto 'http://www.ruby-lang.org/'
Below are details of ...