# Radiant extension and rails method

**URL:** <https://www.ruby-forum.com/t/radiant-extension-and-rails-method/120278>\
**Category:** Radiant CMS\
**Created:** [November 15, 2007, 2:00pm UTC](https://www.ruby-forum.com/t/radiant-extension-and-rails-method/120278 "2007-11-15T14:00:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_des\_Garets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@Marc\_des\_Garets](https://www.ruby-forum.com/u/Marc_des_Garets)\
**Post date:** [November 15, 2007, 2:00pm UTC](https://www.ruby-forum.com/t/radiant-extension-and-rails-method/120278/1 "2007-11-15T14:00:06Z")

</div>

Hi all,

I’m pretty new in radiant and in ruby on rails but I’m making an  
extension for radiant and I have some questions I’m pretty sure you’ll  
be able to answer:

I’m creating my tags for my extension in app/models/solr\_tags.rb

I’m using the method session of the  
ActionController::SessionManagement::ClassMethods class of rails but to  
use this session method I had to add this in my solr\_tags.rb file:

include ActionController::SessionManagement::ClassMethods

After that I can call the method session in my  
lib/flare/controller\_extensions.rb that is in a function I’m calling  
from my solr\_tags.rb file.

But now, I have this error: undefined method `write\_inheritable\_array’  
that I could solve doing an other include of a rails class but I was  
wondering if there is an other way to get all these rails method without  
adding an include each time I need one rails method. Furthermore, it’s  
the method session that is using write\_inheritable\_array so it should be  
fine. I think I have some misconfiguration somewhere. Can you help?

Hope I was clear enough, tell me if not and thank you in advance for  
your help.

Marc

---

<div class="post-metadata">

**Author:** ![Marc\_des\_Garets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@Marc\_des\_Garets](https://www.ruby-forum.com/u/Marc_des_Garets)\
**Post date:** [November 15, 2007, 2:27pm UTC](https://www.ruby-forum.com/t/radiant-extension-and-rails-method/120278/2 "2007-11-15T14:27:05Z")

</div>

Marc,

By default, Radius tags are rendered within a Page that is called from  
the SiteController, which has the session turned off. You might be  
better off using cookies, but you would only be able to read them unless  
you can come up with some scheme that decides what cookies to send based  
on the page. Including that module doesn’t accomplish what you want.  
Could you give us a little more detail about what you want to do?

Sean

---

<div class="post-metadata">

**Author:** ![Marc\_des\_Garets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@Marc\_des\_Garets](https://www.ruby-forum.com/u/Marc_des_Garets)\
**Post date:** [November 15, 2007, 3:07pm UTC](https://www.ruby-forum.com/t/radiant-extension-and-rails-method/120278/3 "2007-11-15T15:07:01Z")

</div>

I think a piece of code will explain better what I want to do:

Here is my solr\_tags.rb:

module SolrTags  
include Radiant::Taggable  
include Flare::ActionControllerExtensions::InstanceMethods  
include ActionController::SessionManagement::ClassMethods

```
...

tag 'solr:facet_list' do |tag|
    @flare = flare_before
    @flare.facet_fields.each do |field|
        %{#{facet_label(field)}}
    end
end

```

end

The flare\_before function in lib/flare/controller\_extensions.rb

def flare\_before  
# TODO: allow source of context to be configurable.  
session[:flare\_context] ||= Flare::Context.new(SOLR\_CONFIG)

```
      @flare = session[:flare_context]

  return @flare

```

end

The method session is part of rails, I can call it thanks to include  
ActionController::SessionManagement::ClassMethods.

Now I have this error message:  
undefined method `write\_inheritable\_array’

This method is called by the method session of rails.

What I want to do is that I don’t have to add include  
ActionController::SessionManagement::ClassMethods and that when I use a  
rails method, this method knows about others rails method.

In short, I want to have access to every rails method.

Marc

---

<div class="post-metadata">

**Author:** ![Marc\_des\_Garets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@Marc\_des\_Garets](https://www.ruby-forum.com/u/Marc_des_Garets)\
**Post date:** [November 16, 2007, 11:26am UTC](https://www.ruby-forum.com/t/radiant-extension-and-rails-method/120278/4 "2007-11-16T11:26:42Z")

</div>

I had to do this i would find a way to refer to the active controller,  
in this case SiteController, and execute my “rails” methods on that  
object.  
Or even do some ugly meta-programming stuff so in your tags “self”  
refers to  
that controller object.

```
There must be an instance or class variable that you can access that

```

gives you a reference to that SiteController instance. Do something  
like  
“puts self.inspect” in your tag to see your “environment” and search for  
something useful.

```
/AITOR
```

---

<div class="post-metadata">

**Author:** ![Marc\_des\_Garets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@Marc\_des\_Garets](https://www.ruby-forum.com/u/Marc_des_Garets)\
**Post date:** [November 15, 2007, 3:40pm UTC](https://www.ruby-forum.com/t/radiant-extension-and-rails-method/120278/5 "2007-11-15T15:40:32Z")

</div>

I just add something to my previous message:

Today I have to do this to call the session method of rails (or any  
other rails method):  
ActionController::SessionManagement::ClassMethods.session

I want to have to do:  
session

without writing the ActionController::SessionManagement::ClassMethods or  
doing an include ActionController::SessionManagement::ClassMethods

Marc

---

<div class="post-metadata">

**Author:** ![Marc\_des\_Garets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@Marc\_des\_Garets](https://www.ruby-forum.com/u/Marc_des_Garets)\
**Post date:** [November 16, 2007, 12:28pm UTC](https://www.ruby-forum.com/t/radiant-extension-and-rails-method/120278/6 "2007-11-16T12:28:53Z")

</div>

Thank you for your answer. Here is what I’ve done. I installed the  
plugin radiant-rails-support that you can find here:  
[http://code.google.com/p/radiant-rails-support/](http://code.google.com/p/radiant-rails-support/)

Now I’ve access to rails method doing this in my app/models/solr\_tags.rb  
(class SolrClass \< SiteController):

module SolrTags  
include Radiant::Taggable

class SolrClass \< SiteController  
def getflare  
session[:flare\_context] ||= Flare::Context.new(SOLR\_CONFIG)  
@flare = session[:flare\_context]  
end  
end

tag ‘solr’ do |tag|  
tag.expand  
end

tag ‘solr:facet\_list’ do |tag|  
s = SolrClass.new  
s.getflare  
end  
end

The problem is that the behaving of this doesn’t seem the same than if I  
do this in app/view/index.rhtml for example and I was wondering if  
someone could explain me why because I am lost.

I get this error when I’m calling the tag solr\_facet\_list  
(\<r:solr:facet\_list\>\</r:solr:facet\_list\>):  
You have a nil object when you didn’t expect it! You might have expected  
an instance of Array. The error occurred while evaluating nil.[]

Marc

---

<div class="post-metadata">

**Author:** ![Marc\_des\_Garets](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@Marc\_des\_Garets](https://www.ruby-forum.com/u/Marc_des_Garets)\
**Post date:** [November 16, 2007, 2:19pm UTC](https://www.ruby-forum.com/t/radiant-extension-and-rails-method/120278/7 "2007-11-16T14:19:06Z")

</div>

When you do “s = SolrClass.new” you are creating a new controller  
instance that has nothing to do with the current request. So seems that  
the  
“session” in “session[:flare\_context]” is nil. This is totally normal.

```
The "class SolrClass < SiteController" doesn't do what you expect.

```

Search this list for “session activation” or something similar, i  
remember  
that in the past someone asked this and finally was able to activate  
them.  
His solution could be the door to what you are looking for.

```
/AITOR
```
