2

I'm new to Ruby so please excuse my ignorance. I really didn't know how to word this question so this may also be part of the reason I haven't found an answer online.

I'm working with Rho Elements, and I'm trying to pass something from one page to another. I've made some good headway but run into something that I do not understand. I can pass through an ID like so

<input type="hidden" name="id" value="<%= @orderdetails.object %>"/>

I then grab the ID(only doing this right now to make sure I do get the ID)

@id = @params['id']

then redirect to another page

redirect url_for(:action => :newpage, :id => @id).

This is where my problems start. When I debug the application I get past the redirect and enter :newpage

def newpage
    @orderdetails = OrderDetails.find(@params['id'])
    if @orderdetails
      render :action => :newpage, :back => url_for(:action => :index)
    else
      redirect :action => :index
    end
end

Once here I check

@params['id] 

and this is what is displayed.

@params {"id"=>"{131113212443313.17}"}  
"id"    ""  

@params {"id"=>"{131113212443313.17}"} is shown by eclipse and when I break into the variable "id" "" is shown.

Why can I see the ID that I want to use to grab the orderdetails that was just created but also have the actual variable be empty?

**EDIT: This is the information I'm trying to pass.

@params {"id"=>"131113212443313.17", "next"=>"asleftnext", "orderdetails"=>
{"AsFoundMeterRead"=>"", "AsFoundImage"=>""}}   
"id"    "131113212443313.17"    
"next"  "asleftnext"    
"orderdetails"  {"AsFoundMeterRead"=>"","AsFoundImage"=>""} 
ArtDlrt
  • 93
  • 7
Chris
  • 41
  • 6

2 Answers2

2

Use params in the controller, not @params. Also the canonical form of accessing keys is params[:id].

harm
  • 10,045
  • 10
  • 36
  • 41
  • Extra information: the `params` hash is actually an instance of `ActiveSupport::HashWithIndifferentAccess` which allows you to access the hash with either a symbol or String key. – MrDanA Feb 26 '13 at 20:16
  • @harm Thanks but I'm still getting nil. I'm going to update quickly with some additional info that might be useful. – Chris Feb 26 '13 at 20:22
0

Like its say in the previous answer you access the params in the controller in this way

@id = params[:id]

Also if you are using Rails 3 or higher you may want to use the new url way is less verbose so its more easy to read.

newpage_controllername_url(:id => @id)

you can also ask for the path with this method.

If you don't know if you are passing right the params you can display the content using

params.inspect

You can view the content of any object with inspect

ArtDlrt
  • 93
  • 7
  • Thanks I'm using eclipse to debug the application and I can see the value is indeed being passed via :id => @id but I'm having trouble getting it out of params. – Chris Feb 26 '13 at 20:52
  • I'm a little confused with the your flow but why don't you try to use sessions if you want to pass values from one view to another. If you already changed your `@params` for `params` there must be something wrong in the flow of the redirects. I tested in my application `@params.inspect` and its empty. You can access session just calling the method and adding a key `session[:id] = @id` but if you don't have the configuration for using the db session store, the session will be saved in a cookie so it will be limited to cookies size and you shouldn't store sensitive data there – ArtDlrt Feb 26 '13 at 22:03
  • I'm using the Rhodes framework which does not support sessions. I think I need to understand more about the framework/ruby before I can begin to understand what is happening. Thanks for the answer but I think it is going to require more digging on my part. – Chris Feb 27 '13 at 17:08
  • Some more updated info: I've found out that when I try to access the :id from the params it is adding on ellipses so my :id is actually {123456789} rather than 123456789. My assumption is that this means it is an array and I need to access like an array. Would that be correct? EDIT: It is a hash my mistake. – Chris Feb 27 '13 at 17:39