Passing params FROM Views TO Controllers -- using form_for, form_tag/select_tag

Hello,

I have 3 methods in a controller (index, choose_table and profile).

The index method simply displays a form_for template where the user
can choose a database name
to use and pass the information to the action :choose_table the
params[:db][:type].

The choose_table action then displays another form_for template where
the user chooses a table
name that will be passed to the the action :profile as params[:table]
[:type].

At the profile method, I then eval the expression using @db_table =
eval("#{@db_env}" + “::” + “#{@table_type}”)
so I can do something like @db_table.find(:all) which evaluates to
Databasename::User.find(:all) or
a @db_table.paginate(:page etc, etc) which evaluates to something like
Databasename:User.paginate(:page etc, etc).

The point is to give the user the ability to choose the database name
and table using Dr. Nic’s
Multiple Connections using the call format to
Object::ModelName.methodname(…).

My question is how do I pass FROM the views TO the controller and
retain information
like the params[:db][:type] and params[:table][:type] which I lose
when coming from a view or views.

What technique can I use to pass back to the controller params[:db]
[:type] and params[:table][:type]
from the views choose_table and profile in this cases, using form_for
and form_tag/select_tag form methods. Passing these

params the other way around (from the
controller to the view) is not a problem. BTW, I am unable to use
session database persistence
because I am dealing with non-standard legacy Oracle databases/tables.

Thanks
rgtorre


##index method in controller
def index
end

##choose_table method in controller
def choose_table
#flash[:notice] = params[:db][:type] # just tried flash
notice…kludgy…awkward way of
#passing params …
end

##profile method in controller
def profile
@db_table = eval("#{@db_env}" + “::” + “#{@table_type}”)
if params[:client_id].nil? or params[:client_id].empty?
@users = @db_table.paginate(:page => params[:page], :order
=> :client_id, :per_page => 10)
else
@users = @db_table.paginate_by_client_id params[:client_id], :page
=> params[:page]
params[:client_id] = nil
end
end

<%= error_messages_for 'db' %> Please Choose a Database Environment: <% form_for :db, :url => { :action => :choose_table } do |form| %>

Database: <%= form.select :type, SourceDb::SOURCE_DB, :prompt => "Select a Database" %>

<%= submit_tag "Continue", :class => "submit" %> <% end %>

<%= error_messages_for ‘table’ %>
Please Choose a SWOT Table:
<% form_for :table, :url => { :action => :profile } do |form| %>



<%=
form.select :type,
SelectTable::SELECT_TABLES,
:prompt => “Select a Table”
%>


<%= submit_tag “Continue”, :class => “submit” %>
<% end %>

<% form_tag :action => :profile do %> Client ID <%= select_tag "client_id", options_for_select([["Select All", nil]] + #@db_table.find(:all, :order => "client_id").map {|a| [a.client_id, a.client_id] }) %> <%= submit_tag "Filter" %> <% end %>

USER <%="#{@db_env}" %>List

<% for user in @users %>
  <tr valign="top" class="<%= cycle('list-line-odd', 'list-line-

even’) %>">

    <td> <%= user.client_id %>                    </td>
    <td> <%= user.field_2 %>                      </td>
    <td> <%= user.field_3 %>                      </td>
    <td> <%= user.field_4 %>                      </td>
    <td> <%= user.field_5 %>                      </td>
    <td> <%= user.field_6 %>                      </td>
    <td> <%= user.field_7.strftime('%m/%d/%Y') %> </td>
    <td> <%= user.field_8 %>                      </td>
    <td> <%= user.field_9.to_i %>                 </td>
    <td> <%= user.field_10 %>                     </td>

  </tr>
<% end %>
Client Id Field 2 Field 3 Field 4 Field 5 Field 6 Field 7 Field 8 Field 9 Field 10
<%= page_entries_info @users %>
<%= will_paginate @users, :container => false %>
-------------------------------------------------------------------------------------------------

On 19 May 2008, at 19:12, rgtorre wrote:

Hello,

At the profile method, I then eval the expression using @db_table =
eval("#{@db_env}" + “::” + “#{@table_type}”)

I would use constantize. What you’ve got there leaves you wide open.

My question is how do I pass FROM the views TO the controller and
retain information
like the params[:db][:type] and params[:table][:type] which I lose
when coming from a view or views.

What technique can I use to pass back to the controller params[:db]
[:type] and params[:table][:type]
from the views choose_table and profile in this cases, using form_for
and form_tag/select_tag form methods. Passing these

hidden_field_tag? or make your routes interesting, ie /profile/foo/bar
runs the profile action for database foo and table bar.

params the other way around (from the
controller to the view) is not a problem. BTW, I am unable to use
session database persistence
because I am dealing with non-standard legacy Oracle databases/tables.

You could still use the session if you wanted (eg with cookiestore).
And the fact that you tried to use the flash indicates your session is
working fine (the flash is stored in the session).

Fred