Displaying 20 results from an estimated 3000 matches similar to: "Writing a Helper function"
2006 Jul 30
8
Method_missing from Ruby for Rails book
I''m having a problem getting this example from the book to work:
class Cookbook
attr_accessor :title, :author
def initialize
@recipes = []
end
def method_missing(m, *args, &block)
@recipes.send(m, *args, &block)
end
end
cb = Cookbook.new
cb << recipe_for_cake
cb << recipe_for_chicken
beef_dishes = cb.find_all {|recipes| recipe.main_ingredient ==
2006 Jul 31
2
[UPDATE] More info on RubyConf 2006 registration
Hi --
Registration for RubyConf 2006 is still scheduled to open on August 2,
in the early evening Pacific (US West Coast) time.
Also, there''s more info at http://www.rubycentral.org/conference
(e.g., the fact that this year we''re only taking credit cards, etc.).
David
P.S. Any LA area Rubyists around? I''ll be there this week doing Rails
training.
--
2006 Aug 08
12
delete_if doesn''t work for has_and_belongs_to_many
I''m using Rails-1.1.4 with Ruby-1.8.4
So let''s say I have 2 model classes:
class Item
has_and_belongs_to_many :things
end
class Thing
has_and_belongs_to_many :items
end
i = Item.new
i.things << Thing.new( :value => "Something").save
i.things << Thing.new( :value => "Something Else" ).save
i.save
Fine, now I have two records in the
2006 Sep 29
2
ApplicationHelper is not a parent of SomeHelper?
i have:
# file application_helper.rb
module ApplicationHelper
def load_components
@right_sidebar = ''some stuffs''
end
end
# file user_public/blog_helper.rb
module UserPublic::BlogHelper
def load_components
ApplicationHelper.load_components
@right_sidebar += ''{blog archive}''
end
end
the problem is, i want to load the
2006 Jul 17
14
REST Relationship Models
I''m trying to figure out an elegant way to do this:
I have the following three tables:
people, employer, employees
And consequently the following three models:
class Person < ActiveRecord::Base
end
class Employer < ActiveRecord::Base
has_many :employees
end
class Employee < ActiveRecord::Base
belongs_to :person
belongs_to :employer
end
I want to be able to say:
2006 Aug 01
4
class def error when serving "stand-alone" rhtml files
I''m attempting to set up a rails app so that I can add rhtml files
without having to create controllers for each one. I want a simple
solution to serving static-like rhtml files as well as those with a
little logic. The solution I found is this one:
I added the following controller
static_controller.rb
#####################
class StaticController < ApplicationController
end
I
2006 Aug 10
6
Partials - asked before never got reply
I''m trying to figure out how multiple partials in one page would be
configured when they are based on some action in the controller.
As an example -
I have a main/welcome page. If someone new or a user not logged in
arrives at this page I display both a registration form and a login
form. However, if they are logged in then those forms should not show
up on that page. Also should
2006 Jul 26
2
newbie - HABTM confused...
I have a users table. I have a assignment table. and I have to log in
to see my assignments. i can and I hasve a session id.
I can make a new assignment and save my id in the user_id field of the
assigment table.
I want to share my assignments. so I can create a assignments_users
table. this way I can have assignment 1 shared with user 1 and 2. and
If I log in as user 1 or 2 I see the assignment.
2006 Oct 30
7
belongs_to nonintuitive results with assignment?
class Page < ActiveRecord::Base
has_many :lists
end
class List < ActiveRecord::Base
belongs_to :page
end
######### controller code, inside action:
list = List.find(params[:id])
old_page = list.page
list.page = new_page
# what is the value of old_page now?
old_page now is the same as new_page! what the heck?!?
The only thing i can think of is that old_page is
2006 Aug 01
4
How do you evaluate text as code in Ruby?
How do you evaluate text as code in Ruby?
I''m sure there''s a technical term for this...
Thanks
Chris
--
Posted via http://www.ruby-forum.com/.
2006 Aug 02
2
Feature request
Is there a place for feature requesting?
Rails uses the "@" prefix for vars in the request scope, why not add a
prefix for the session scope? Instead of "session[:myvar]" it could then
be something like "%myvar".
--
Posted via http://www.ruby-forum.com/.
2006 Aug 07
2
Getting an array of ids from form checkboxes?
Is it possible to set up a list of checkboxes so that the form
parameters are given in an array (eg {"delete_list" => [3,6,7]}) ?
At the moment I''m using
<%= check_box_tag "delete_list[#{post.id}]" %>
...which gives parameters looking like {"delete_list" => {"3" => "1",
"6" => "1",
2006 Aug 08
1
form parameter
How can I change some parameters in a function of the controller. I have
a User_Controller, who''s responsible for update the information fields
in the database.
The parameters are "id", "firstname" and "lastname". Now, I want to
manipulate parameter "lastname", because I would like to add at the end
a point.
>> Thomas Miller
2006 Sep 03
2
Undefined method "xxx" of a model when calling a helper
Hi all
I''m creating a shop page. I have a cart model that looks like the
following:
class Cart
attr_reader :line_items
def get_line_item id
@line_items.each do |l|
return l if l.id == id
end
end
def initialize
@line_items = []
end
def empty!
initialize
end
def empty?
return true if @line_items.empty?
false
end
end
And I have some
2006 Aug 13
4
Experienced RoR Coders Needed!
Devlounge is looking for advanced RoR coders who may be willing to share
their knowledge by writting quality articles on Ruby and what it can
accomplish. These can be tutorials, discussions, opinion pieces, getting
started guides, etc. You''re articles will be seen by 350-500 unique
people daily! Plus, you''ll get a great link back in our killer authors
index.
To apply to be
2006 Sep 28
2
RHTML page not rendering properly
I''ve got a weired problem. I got a RHTML page which is not rendered
properly in the browser all other pages in my app do renders correctly.
Only this one page returns the page''s HTML with the following header
Content-Type: text/html
Set-Cookie: _session_id=cb3c140fd4ef907c99ef203a053fba1a; path=/
Status: 200 OK
Cache-Control: no-cache
<html>
.....................
2006 Oct 05
2
update_attributes
I''m working on a form that updates a product record and several
associated detail records.
The detail records are showing and populating okay in the form. But
when it hits the controller, I get Couldn''t find Detail with ID=detail
AND (details.product_id = 38). The :detail params seem to refer to the
correct record id. Anyone have an idea how to fix this?
Here''s the
2006 Aug 08
1
Best way to get data from n+1 models
Hello there.
Sometime ago I asked was the best way to retrieve data like an "union
all", and unfortunely I could not find the URL on the forum. I asked
about, for example, hotel rooms and reservation. On another case, I
could ask for a plane occupation: a model that takes care of the sold
tickets and another one with the reservations. To get the full map of
the plane I need to get
2006 Nov 04
2
Possible to use attr_reader/writer in model?
I have some properties that I want setable externally, but readable only
internally. I''ve played around with attr_writer (and attr_reader
separately) but can''t figure out how to get either to work. I can do
what I want using attr_accessor, or just straight out defining the prop
setter method. Anybody know how to use attr_writer or attr_reader with a
model?
You da man,
Joe
2006 Nov 09
2
redefining the method belongs_to in ActiveRecord::Base
Hi. I''ve tried to redefine the method belongs_to in ActiveRecord::Base,
so every time a model is defined as belonging to :attachment, it should
have some additional methods. I tried to do an alias of belongs_to, but
this was not successful. The error message in Webrick was
> Booting WEBrick...
./script/../config/../lib/ActiveRecordExtensions.rb:67: undefined
method