What are options used for?

Hello,

I actually have few simple questions which I cannot find a answer for in
the documentation?

1#
In most of the methods in rails I find the parameter options={} which I
don’t know what it can include? Can somebody explain this one to me
please :slight_smile:

2#
if parent_id.nil?
link_to “Create link”, :action => :create
else
link_to “Create link”, :action => :create, :id => parent_id
end

Can’t I do this by DRY? I cannot figure out how to add the if in the
link_to so when parent_id is nil it doesn’t throw exception about that.

3#
Why do I recieve exception when I type this while using the act_as_tree

@pages = Page.find( :all, :conditions => ‘parent_id IS NULL’, :include
=> :children)


I hope someone can help me through some of them, so I can keep working
on my little project, and thanks in advance for any help :smiley:

//Jamal

#1

I fixed #1 just with, weird it works now.
link_to “Create page”, { :action => :create, :id => parent_id }

Jamal S. wrote:

#1

I fixed #1 just with, weird it works now.
link_to “Create page”, { :action => :create, :id => parent_id }

I meant to say #2, sorry :slight_smile:

Hi jamal,

your 2nd problem got solved b’coz, you combined :id and :actions as
one object(meaning one parameter to link_to, so second parameter to
link to is options, which
is a hash like structure, where you can pass all your arguements), if
you don’t put those flower brace, it won’t work b’coz it
assumes, :action as second argument
and :id as third argument(which is html_options, nothing but all the
possible html tag attributes like id, name, style, class etc…).

And in your 3rd question, can you please show what exception it
throws, and what does :include => :children mean.
Are you sure, is there any standard argument to find with :children as
the value of :include key?

On Aug 25, 1:30 am, Jamal S. [email protected]