I am having some difficulty conceiving how to best address a parameter passing problem I am having with rails. I am sure that this has been encountered and solved by others so perhaps someone can illuminate my ignorance. I have the following models: Entity has_many :locations has_many :site_locations, :include => :sites has_many :sites, :through => :site_locations Site has_many :locations Location belongs_to :entity belongs_to :site Typically a site is created together with a location. The call from entities/index looks like this: <% if entity.locations.empty? -%> <%= link_to ''Add Locations'', new_entity_location_path(entity) -%> <% else -%> which passes this params hash to the locations_controller action new: entity_id: "3" action: new controller: locations What I require is for the value {:entity_id => ''3'' } to be retained and passed back to the controller for the subsequent locations/show view. I tried doing this in the locations/new view: <% hidden_field_tag :entity_id, params[:entity_id].to_s -%> but that did not work. How do I accomplish this? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
save it to the session maybe? On Mon, Apr 28, 2008 at 12:27 PM, James Byrne <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I am having some difficulty conceiving how to best address a parameter > passing problem I am having with rails. I am sure that this has been > encountered and solved by others so perhaps someone can illuminate my > ignorance. > > > I have the following models: > > Entity > has_many :locations > has_many :site_locations, :include => :sites > has_many :sites, :through => :site_locations > > Site > has_many :locations > > Location > belongs_to :entity > belongs_to :site > > Typically a site is created together with a location. The call from > entities/index looks like this: > > <% if entity.locations.empty? -%> > <%= link_to ''Add Locations'', > new_entity_location_path(entity) -%> > <% else -%> > > which passes this params hash to the locations_controller action new: > > entity_id: "3" > action: new > controller: locations > > > What I require is for the value {:entity_id => ''3'' } to be retained and > passed back to the controller for the subsequent locations/show view. I > tried doing this in the locations/new view: > > <%> hidden_field_tag :entity_id, params[:entity_id].to_s > -%> > > but that did not work. How do I accomplish this? > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Roger Pack wrote:> save it to the session maybe? > > On Mon, Apr 28, 2008 at 12:27 PM, James ByrneI am not sure that that would be the correct thing to do. This is not a session variable but a request variable. What I have is the situation where location.id = ''x'' and location.entity_id = ''y''. Now, in the locations_controller I need to lookup entities via entity_id. What I desire is to pass entity_id, which is in params[] already when the locations/new view is presented, from this view back to the locations_controller via params. I cannot recall how do do this in the present instance. Perhaps I have to pass it as an optional parameter in the submit action. I had thought that initializing a hidden field would accomplish this, but evidently I was wrong. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
double check your hidden field settings http://betterlogic.com/roger/?p=204 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---