Accessing params in actionview


#1

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 :slight_smile:


#2

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
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 :wink:

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

-Rob

I’m stuck :slight_smile:

Posted via http://www.ruby-forum.com/.

Rob B. http://agileconsultingllc.com
removed_email_address@domain.invalid


#3

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 :wink:

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 :slight_smile:

Thanks again I’ll try tomorrow . Here is :slight_smile: already tomorrow


#4

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

I haven’t patience till morning

Long live rails community :slight_smile: