Accessing Name and value pair using "Sinatra"

Hello everyone,

   I currently using Sinatra nad i must say its great.
   But I am currently stuck i wanted to passes a Name,value pair
   as a parameter to sinatra

   something like this
   http://localhost:4567/multiQuery?&Name_1=‘ABC’&Name_2=‘XYZ’&Name_3=‘LMN’

   so that i can directly access values 'ABC','XYZ' and 'LMN'

thanks anyway

···

--
Posted via http://www.ruby-forum.com/.

There's a params attribute in Sinatra::Base that contains the query string:

This route:

get '/hello/:name' do |name|
        "Hello, #{name}. #{params.inspect}"
end

when called as:

http://localhost:4567/hello/x?a=3&b=4

produces:

Hello, x. {"name"=>"x", "a"=>"3", "b"=>"4"}

Hope this helps,

Jesus.

···

On Tue, Sep 8, 2009 at 9:00 AM, Ken Ghosh<meetme2meat@gmail.com> wrote:

Hello everyone,

I currently using Sinatra nad i must say its great.
But I am currently stuck i wanted to passes a Name,value pair
as a parameter to sinatra

something like this
http://localhost:4567/multiQuery?&Name_1=‘ABC’&Name_2=‘XYZ’&Name_3='LMN&#39;

so that i can directly access values 'ABC','XYZ' and 'LMN'

Jesús Gabriel y Galán wrote:

Hello everyone,

� I currently using Sinatra nad i must say its great.
� But I am currently stuck i wanted to passes a Name,value pair
� as a parameter to sinatra

� something like this
http://localhost:4567/multiQuery?&Name_1=‘ABC’&Name_2=‘XYZ’&Name_3='LMN&#39;

� so that i can directly access values 'ABC','XYZ' and 'LMN'

There's a params attribute in Sinatra::Base that contains the query
string:

This route:

get '/hello/:name' do |name|
        "Hello, #{name}. #{params.inspect}"
end

when called as:

http://localhost:4567/hello/x?a=3&b=4

produces:

Hello, x. {"name"=>"x", "a"=>"3", "b"=>"4"}

Hope this helps,

Jesus.

can i get only parameters after the question '?'
e.g
   http://localhost:4567/hello/x?a=3&b=4
as
  {"a" => "3","b" => "4"}
also i want to know how can i return and xml content

so that when i type
http://localhost:4567/hello/x?a=3&b=4
the response should be presented in xml format

···

On Tue, Sep 8, 2009 at 9:00 AM, Ken Ghosh<meetme2meat@gmail.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

Yes, you get also the name because the route contains variables.
If you change it to:

get '/hello/x' do
         "Hello, . #{params.inspect}"
end

Jesus.

···

On Tue, Sep 8, 2009 at 2:20 PM, Ken Ghosh<meetme2meat@gmail.com> wrote:

Jesús Gabriel y Galán wrote:

On Tue, Sep 8, 2009 at 9:00 AM, Ken Ghosh<meetme2meat@gmail.com> wrote:

Hello everyone,

� I currently using Sinatra nad i must say its great.
� But I am currently stuck i wanted to passes a Name,value pair
� as a parameter to sinatra

� something like this
http://localhost:4567/multiQuery?&Name_1=‘ABC’&Name_2=‘XYZ’&Name_3='LMN&#39;

� so that i can directly access values 'ABC','XYZ' and 'LMN'

There's a params attribute in Sinatra::Base that contains the query
string:

This route:

get '/hello/:name' do |name|
"Hello, #{name}. #{params.inspect}"
end

when called as:

http://localhost:4567/hello/x?a=3&b=4

produces:

Hello, x. {"name"=>"x", "a"=>"3", "b"=>"4"}

can i get only parameters after the question '?'
e.g
http://localhost:4567/hello/x?a=3&b=4
as
{"a" => "3","b" => "4"}

For the XML response:
http://sinatra.rubyforge.org/api/classes/Sinatra/Builder.html

···

--
Posted via http://www.ruby-forum.com/.

Michael Tomer wrote:

For the XML response:
http://sinatra.rubyforge.org/api/classes/Sinatra/Builder.html

please help with these code in mind

####### this is my sinatra code############3

get '/multiquery.xml' do
  content_type('text/xml')
  array_of_names = params[:name]
  '#{construct_xml(array_of_names)}'
end

the method construct_xml look like this

  def construct_xml(names)
    xml = Builder::XmlMarkup.new(:indent =>1)
    xml.instruct!
    names.each do |name|
        xml.queryresponse {
        xml.name "#{name}"
        xml.credential "Engineer"
      }
    end
    return xml
  end

Now the point is that the method "construct_xml" construct the
appropriate xml
but the the xml doesn't appear in browser
and the line of code '#{construct_xml(array_of_name)}' run into "XML
Parsing Error: not well-formed"

iam sure that xml is formed properly.i mean to say the i have set the
:target => $stdout

like this
Builder::XmlMarkup.new(:target =>$stdout ,:indent =>1)
and the xml is constructed properly in console
ent .Is there any thing that I am missing.

please reply

thanks anyway

···

--
Posted via http://www.ruby-forum.com/\.

Ken Ghosh wrote:

####### this is my sinatra code############3

get '/multiquery.xml' do
  content_type('text/xml')
  array_of_names = params[:name]
  '#{construct_xml(array_of_names)}'
end

Single quotes prevent any expansion taking place. In this case, you are
literally returning the string

  #{construct_xml(array_of_names)}

to the browser.

Use double quotes, or better, just omit the "#{...}" construction
entirely, since you're just putting a string inside a string.

···

--
Posted via http://www.ruby-forum.com/\.