# Accessing params in actionview

**URL:** <https://www.ruby-forum.com/t/accessing-params-in-actionview/157357>\
**Category:** Rails\
**Created:** [January 9, 2009, 9:06pm UTC](https://www.ruby-forum.com/t/accessing-params-in-actionview/157357 "2009-01-09T21:06:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kfl62](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@kfl62](https://www.ruby-forum.com/u/kfl62)\
**Post date:** [January 9, 2009, 9:06pm UTC](https://www.ruby-forum.com/t/accessing-params-in-actionview/157357/1 "2009-01-09T21:06:24Z")

</div>

Hi

I need something like :

```
<% obj = params[:obj].find(params[:obj_id]) %>
<textarea id="mce_edit" style="height:430px; width:100%;">
  <%= obj.params[:obj_method] %>
</textarea>

```

in a partial. params[:obj] and params[:obj\_method] are strings like  
TrstSysPage, title. params[:obj\_id] is number and is only working for  
the rest I got

undefined method `params’ for #Enumerable::Enumerator:0xb4b38b48

Extracted source (around line #17):

14:   
15: \<% obj = params[:obj].find(params[:obj\_id]) %\>  
16:   
17: \<%= obj.params[:obj\_method] %\>  
18:   
19:

I’m stuck 🙂

---

<div class="post-metadata">

**Author:** ![kfl62](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@kfl62](https://www.ruby-forum.com/u/kfl62)\
**Post date:** [January 9, 2009, 10:22pm UTC](https://www.ruby-forum.com/t/accessing-params-in-actionview/157357/2 "2009-01-09T22:22:06Z")

</div>

On Jan 9, 2009, at 3:06 PM, Ferenc-Lorant Kiss wrote:

> Hi
> 
> I need something like :
> 
> \<% obj = params[:obj].find(params[:obj\_id]) %\>

Well, you need to look at the documentation for  
ActiveSupport::Inflector.constantize and Object#send

[http://www.railsbrain.com/api/rails-2.1.2/doc/index.html?a=M000945&name=constantize](http://www.railsbrain.com/api/rails-2.1.2/doc/index.html?a=M000945&name=constantize)  
ri Object#send

params[:obj].constantize.find(params[:obj\_id]).send(params[:obj\_method])

But you should know that this is potentially disastrous, say if params  
has {:obj =\> “ImportantModel”, :obj\_id =\> “1”, :obj\_method =\>  
“destroy”}. (Repeat with all other values for :obj\_id 😉

Note also that you don’t check for any exceptions (such as  
ActiveRecord::RecordNotFound or NoMethodError)

-Rob

> ## I’m stuck 🙂
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![kfl62](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@kfl62](https://www.ruby-forum.com/u/kfl62)\
**Post date:** [January 9, 2009, 11:04pm UTC](https://www.ruby-forum.com/t/accessing-params-in-actionview/157357/3 "2009-01-09T23:04:24Z")

</div>

Rob B. wrote:

> params[:obj].constantize.find(params[:obj\_id]).send(params[:obj\_method])
> 
> But you should know that this is potentially disastrous, say if params  
> has {:obj =\> “ImportantModel”, :obj\_id =\> “1”, :obj\_method =\>  
> “destroy”}. (Repeat with all other values for :obj\_id 😉
> 
> Note also that you don’t check for any exceptions (such as  
> ActiveRecord::RecordNotFound or NoMethodError)

Thanks!  
I use this just for edit some html data with mceEdit. All params comes  
from regularly checked edit form, but I needed a new screen/window for  
those text fields 🙂

Thanks again I’ll try tomorrow . Here is 🙂 already tomorrow

---

<div class="post-metadata">

**Author:** ![kfl62](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@kfl62](https://www.ruby-forum.com/u/kfl62)\
**Post date:** [January 9, 2009, 11:15pm UTC](https://www.ruby-forum.com/t/accessing-params-in-actionview/157357/4 "2009-01-09T23:15:34Z")

</div>

You are the best!!! It’s working !

I haven’t patience till morning

Long live rails community 🙂
