please can some one explain how to solve this problem …
how do you route the http get data from a form currently it produces a
url like this > http://10.1.0.10/admin/view/7?number=1
i would like it be like this > http://10.1.0.10/admin/view/7/1
how could i do this ?
andrew
Add to your routes
map.connect “:controller/:action/:id/:number”, :controller => ‘admin’,
:action
=> ‘view’, :id => /^\d+$/, :number => /^\d+$/
Kent.
ksruby wrote:
Add to your routes
map.connect “:controller/:action/:id/:number”, :controller => ‘admin’,
:action
=> ‘view’, :id => /^\d+$/, :number => /^\d+$/
Kent.
thanks that’s solved part of the problem i can now enter the url
manualy
the thing forgot to say was that im trying to use a dropdown box on a
form to the generate the url ie you select the item number for the
drop down but when i submit the form i would like the url to come out as
:controller/:action/:id/:number(http://10.1.0.10/admin/view/7/2) but
it come up as http://10.1.0.10/admin/view/7/1?number=2
any idea’s how to sovle that bit?
I don’t know how your form looks like, but if you have this rule in your
routes
map.connect ‘admin/view/:id/:number’, :controller => ‘admin’, :action =>
‘view’, :id => /^\d+$/, :number => /^\d+$/
then
<%= url_for :controller => ‘admin’, :action => ‘view’, :id => 3, :number
=> 4
%>
generates
http://your-site/admin/view/3/4
Kent.
Well, in this case form_tag method’s already generated the url for the
submit
action. It doesn’t know about the :number part. So in this case Rails
can’t
help you, it’s your browser that appends ?number= query parameter. You
can
change form action with javascript though.
Kent.
ksruby wrote:
I don’t know how your form looks like, but if you have this rule in your
routes
map.connect ‘admin/view/:id/:number’, :controller => ‘admin’, :action =>
‘view’, :id => /^\d+$/, :number => /^\d+$/
then
<%= url_for :controller => ‘admin’, :action => ‘view’, :id => 3, :number
=> 4
%>
generates
http://your-site/admin/view/3/4
Kent.
if it’s any help here’s the code for the form :
<%= form_tag({ :action => “view”, :id => @chapter.fanfics_id },{:method
=>“get”,:name =>“form1”}) %>
<%=options_from_collection_for_select(@menu, "number", "title",
selected_value =[@chapter.number,@chapter.title]) %>
<%= end_form_tag %>
and the controller :
def view
id = ((params[:id]))
num = @params[“number”]
if num == nil
num = 1
else
end
@number=num
@chapter = Chapter.find_by_fanfics_id_and_number((params[:id]),num)
@menu = Chapter.find_by_sql [" SELECT * FROM chapters WHERE fanfics_id
= ?",id]
end
end
ksruby wrote:
Well, in this case form_tag method’s already generated the url for the
submit
action. It doesn’t know about the :number part. So in this case Rails
can’t
help you, it’s your browser that appends ?number= query parameter. You
can
change form action with javascript though.
Kent.
ok thanks any way
is there any way of getting the same effect with out useing forms
or would it be best to replace the dropdown box with a row of
hyperlinks