/#action Route in Routes.rb in Ruby on Rails
The actual URL you are visiting there is http://lala.com/
. The server does not see the #album/some-album-id
piece, the fragment identifier. That is seen solely by the browser.
There is a growing trend of building MVC apps with the views and controllers in the client/browser, rather than on the server. The application is implemented with JavaScript in the client, instead of with Ruby on the server. The server essentially becomes the API or the data-access layer, rather than being the piece that renders HTML.
Add new action to route
in your config/routes.rb file do this
resources :users do
collection do
get 'another_new'
post 'another_create'
end
end
Also have a look HERE for clear understanding of concepts.
Hope this helps you dude :)
How does routes of Ruby On Rails know which controller to hit when we hit an url
It's a way to redirect incoming requests to controllers and actions. It replaces the mod_rewrite rules. Best of all, Rails' Routing works with any web server. Routes are defined in app/config/routes.rb.
Think of creating routes as drawing a map for your requests. The map tells them where to go based on some predefined pattern.
The routes.rb file defines the actions available in the applications and the type of action such as get, post, and patch.
like:
get 'photos/:id' => 'photos#show', :defaults => { :format => 'jpg' }
the normalise value of above route is.
app: #<ActionDispatch::Routing::RouteSet::Dispatcher:0x007fd05e0cf7e8
@defaults={:format=>"jpg", :controller=>"photos", :action=>"show"},
@glob_param=nil,
@controller_class_names=#<ThreadSafe::Cache:0x007fd05e0cf7c0
@backend={},
@default_proc=nil>>
conditions: {:path_info=>"/photos/:id(.:format)", :required_defaults=>[:controller, :action], :request_method=>["GET"]}
requirements: {}
defaults: {:format=>"jpg", :controller=>"photos", :action=>"show"}
as: nil
anchor: true
How to add a custom route, controller, and action in Ruby on Rails?
routes.rb:
get 'heartbeat' => "custom_controller#heartbeat"
custom_controller.rb:
class CustomController < ApplicationController
def heartbeat
render inline: "Some string to the client/user"
end
end
Rails add route for additional method action
You still need to declare the routes in your config\routes.rb
file.
Also, if you want to use more idiomatic ruby (which you do), you should be using underscored method names, not camelCase. e.g. device_connect_edit
NOT deviceConnectEdit
. You'll run into headaches down the road if you don't conform to the convention (unless you have a very good reason for departing from it). In that light I'll post the routes in idiomatic Ruby and hope you update your method names :-)
resources :users do
member do
get 'device_connect_edit'
post 'device_connect_update'
end
end
Also, you might want to strongly consider your design to have a separate device
resource instead of tacking it on in the UsersController...
Routing for sessions#destroy action
It is best to treat the routes to your sessions controller as a singular resource
routes.rb
resource :sessions
Doc: http://guides.rubyonrails.org/routing.html#singular-resources
This will give you a route that you can use without ID's
DELETE /sessions sessions#destroy
Related Topics
Import CSV in Batches of Lines in Rails
Testing HTML5 File Upload with Capybara/Selenium Webdriver - Ruby
Where Are Catch and Throw Useful in Ruby
Chromedriver Devtools Port Number Error
Algorithm to Shuffle an Array Randomly Based on Different Weights
Recursively Convert Hash Containing Non-Utf Chars to Utf
Can't Find a Route with an Underscore or Doesn't Treat It Properly
How to Create Zip File Only in Memory in Ruby
Error in Install Ruby-Debug-Base on Ruby 2.0.0P247
Count Iteration on the Enumerable Cycle
Nginx Getting Permission Denied When Connecting to Unicorn
Array#Uniq with Block Equivalent in Ruby 1.8.7
How to Stop Chromedriver from Opening Settings Tab Automatically
Ruby- Delete a Value from Sorted (Unique) Array at O(Log N) Runtime