Jump to content

The ultimate community for Ruby on Rails developers.


Photo

what is the use of {:type = >"some string"} in rake routes

rake routes

  • Please log in to reply
6 replies to this topic

#1 Varun_krishna

Varun_krishna

    Signalman

  • Members
  • 23 posts

Posted 27 May 2014 - 09:41 AM

Hi everyone recently I had seen something like this is in some discussion forum, but unfortunately I had forgotten where I had seen this

The following is the extract from the rake routes

somepage         GET        /somepage/:id (.:format)     controller#action {:type => "some string"}

 

So here my question is what is the use of {:type => "some string' } in the routes ? what does it do ?

 

 

 

 

 

Thanks

Varun Krishna. P



#2 Ohm

Ohm

    Driver

  • Moderators
  • 469 posts
  • LocationCopenhagen

Posted 27 May 2014 - 10:26 AM

How is it defined in your routes.rb-file?


Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk


#3 Varun_krishna

Varun_krishna

    Signalman

  • Members
  • 23 posts

Posted 28 May 2014 - 05:02 AM

@Ohm

The routes.rb looks something like this

 

...

...

resources :purchaseditems, :controller  => :items, :type =>" some string"

....

...

 

Thanks

Varun Krishna. P



#4 Ohm

Ohm

    Driver

  • Moderators
  • 469 posts
  • LocationCopenhagen

Posted 28 May 2014 - 06:26 AM

Having fooled a bit around in my own routes file, I'd say that all it does it add type with the value "some string" to your params hash in the call.


Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk


#5 Varun_krishna

Varun_krishna

    Signalman

  • Members
  • 23 posts

Posted 28 May 2014 - 06:51 AM

Ohm

Thanks for that answer, and I have another doubt from your answer, you had mentioned something like params hash, and I don't get what is that, could you please help me with understanding the term params hash  and how does it look like (syntax) and where could I find more information about that?

 

 

Thanks

Varun Krishna. P



#6 Ohm

Ohm

    Driver

  • Moderators
  • 469 posts
  • LocationCopenhagen

Posted 28 May 2014 - 08:02 AM

If you have an URL like http://www.example.o...tionality=Greek you'll get a params hash containing

{
  title: 'Sparta',
  nationality: 'Greek'
}

Had you also had type: 'Country' in your routes, this would have been added to the params hash, but not the URL.

 

You can access the params hash via params in your controllers:

def index
  @sparta = (params[:title] == 'Sparta')
end

Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk


#7 Varun_krishna

Varun_krishna

    Signalman

  • Members
  • 23 posts

Posted 28 May 2014 - 08:57 AM

Ohm

Thanks for your reply.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users