Forum: Ruby on Rails Accessing params in actionview

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ferenc-Lorant K. (Guest)
on 2009-01-09 22:06
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:   <body style="background-color : #AFAFAF; padding: 10px 10px 0
10px;">
15:     <% obj = params[:obj].find(params[:obj_id]) %>
16:     <textarea id="mce_edit" style="height:430px; width:100%;">
17:       <%= obj.params[:obj_method] %>
18:     </textarea>
19:     <p style="padding: 15px 0 0 10px">

I'm stuck :)
Rob B. (Guest)
on 2009-01-09 23:22
(Received via mailing list)
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/inde...
  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/.

Rob B.    http://agileconsultingllc.com
removed_email_address@domain.invalid
Ferenc-Lorant K. (Guest)
on 2009-01-10 00:04
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
Ferenc-Lorant K. (Guest)
on 2009-01-10 00:15
You are the best!!! It's working !

I haven't patience till morning

Long live rails community :)
This topic is locked and can not be replied to.