routing to users device - ruby-on-rails

iam trying to remember how to code since 3 months of stoping, so in my new project trying to add a link_to that goes to the device users sign_in page..kept getting this error.
NameError in Topics#index
undefined local variable or method `new_user_session' for #<#<Class:0x74e5db0>:0x54af248>
route.rb
Rails.application.routes.draw do
resources :topics
devise_for :admins, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users
root 'topics#index'
here is my routes
Prefix Verb URI Pattern Controller#Action
topics GET /topics(.:format) topics#index
POST /topics(.:format) topics#create
new_topic GET /topics/new(.:format) topics#new
edit_topic GET /topics/:id/edit(.:format) topics#edit
topic GET /topics/:id(.:format) topics#show
PATCH /topics/:id(.:format) topics#update
PUT /topics/:id(.:format) topics#update
DELETE /topics/:id(.:format) topics#destroy
new_admin_session GET /admin/login(.:format) active_admin/devise/sessions#new
admin_session POST /admin/login(.:format) active_admin/devise/sessions#create
destroy_admin_session DELETE|GET /admin/logout(.:format) active_admin/devise/sessions#destroy
admin_password POST /admin/password(.:format) active_admin/devise/passwords#create
new_admin_password GET /admin/password/new(.:format) active_admin/devise/passwords#new
edit_admin_password GET /admin/password/edit(.:format) active_admin/devise/passwords#edit
PATCH /admin/password(.:format) active_admin/devise/passwords#update
PUT /admin/password(.:format) active_admin/devise/passwords#update
admin_root GET /admin(.:format) admin/dashboard#index
batch_action_admin_admins POST /admin/admins/batch_action(.:format) admin/admins#batch_action
admin_admins GET /admin/admins(.:format) admin/admins#index
POST /admin/admins(.:format) admin/admins#create
new_admin_admin GET /admin/admins/new(.:format) admin/admins#new
edit_admin_admin GET /admin/admins/:id/edit(.:format) admin/admins#edit
admin_admin GET /admin/admins/:id(.:format) admin/admins#show
PATCH /admin/admins/:id(.:format) admin/admins#update
PUT /admin/admins/:id(.:format) admin/admins#update
DELETE /admin/admins/:id(.:format) admin/admins#destroy
admin_dashboard GET /admin/dashboard(.:format) admin/dashboard#index
batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action
admin_users GET /admin/users(.:format) admin/users#index
POST /admin/users(.:format) admin/users#create
new_admin_user GET /admin/users/new(.:format) admin/users#new
edit_admin_user GET /admin/users/:id/edit(.:format) admin/users#edit
admin_user GET /admin/users/:id(.:format) admin/users#show
PATCH /admin/users/:id(.:format) admin/users#update
PUT /admin/users/:id(.:format) admin/users#update
DELETE /admin/users/:id(.:format) admin/users#destroy
admin_comments GET /admin/comments(.:format) admin/comments#index
POST /admin/comments(.:format) admin/comments#create
admin_comment GET /admin/comments/:id(.:format) admin/comments#show
DELETE /admin/comments/:id(.:format) admin/comments#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root GET / topics#index
index.erb
<div id="pre_header" class="visible-lg" style="background-color:#E4AB7E; height:5px;"></div>
<div id="header" class="container" style="background-color:#fff; background-image:none;">
<div class="row">
<!-- Logo -->
<div class="logo">
<%= link_to (image_tag 'logo.jpg',:style=>'padding:20px 50px;'), root_path %>
</div>
<!-- End Logo -->
<!-- Top Menu -->
<div class="col-md-12 margin-top-30">
<div id="hornav" class="pull-right visible-lg">
<ul class="nav navbar-nav">
<li><%= link_to 'Laman Utama', topics_path %></li>
<li>Senarai Ilmu</li>
<li>Hubungi Kami</li>
<li>Info Lanjut</li>
<li><%= link_to 'Log Masuk',new_user_session %></li>
</ul>
</div>
</div>
<div class="clear"></div>
<!-- End Top Menu -->
</div>
</div>
<div id="pre_header" class="visible-lg" style="background-color:#E4AB7E; height:5px;"></div>

It's a typo I guess. path is missing in the link. It would be new_user_session_path
<li><%= link_to 'Log Masuk',new_user_session_path %></li>

Related

I am having trouble with the form in rails

How can i store image Tags in Tag model. I have albums controller in which i have images on show page .. and in those particular images i want to save tags when i enter.
My albums controller :
class AlbumsController < ApplicationController
before_action :authenticate_user!
def index
#albums = current_user.albums.all
end
def show
#album= current_user.albums.find(params[:id])
end
def new
#album = current_user.albums.new
end
def create
#album = current_user.albums.new(album_params)
if #album.save
redirect_to albums_path
else
render :new
end
end
def edit
#album =current_user.albums.find(params[:id])
end
def update
#album = current_user.albums.find(params[:id])
if #album.update(album_params)
redirect_to albums_path
else
render :edit
end
end
def destroy
#album = current_user.albums.find(params[:id])
#album.destroy
redirect_to albums_path
end
def delete_image_attachment
#image = ActiveStorage::Attachment.find(params[:id])
#image.purge
redirect_to albums_path
end
private
def album_params
params.require(:album).permit(:title, :desciption, images: [])
end
end
My routes.rb file :
Rails.application.routes.draw do
devise_for :users
root to: "albums#index"
resources :albums do
member do
delete :delete_image_attachment
end
resources :comments
resources :tags
end
end
And rails routes are:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
user_password PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
POST /users/password(.:format) devise/passwords#create
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
user_registration PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
POST /users(.:format) devise/registrations#create
root GET / albums#index
delete_image_attachment_album DELETE /albums/:id/delete_image_attachment(.:format) albums#delete_image_attachment
album_comments GET /albums/:album_id/comments(.:format) comments#index
POST /albums/:album_id/comments(.:format) comments#create
new_album_comment GET /albums/:album_id/comments/new(.:format) comments#new
edit_album_comment GET /albums/:album_id/comments/:id/edit(.:format) comments#edit
album_comment GET /albums/:album_id/comments/:id(.:format) comments#show
PATCH /albums/:album_id/comments/:id(.:format) comments#update
PUT /albums/:album_id/comments/:id(.:format) comments#update
DELETE /albums/:album_id/comments/:id(.:format) comments#destroy
album_tags GET /albums/:album_id/tags(.:format) tags#index
POST /albums/:album_id/tags(.:format) tags#create
new_album_tag GET /albums/:album_id/tags/new(.:format) tags#new
edit_album_tag GET /albums/:album_id/tags/:id/edit(.:format) tags#edit
album_tag GET /albums/:album_id/tags/:id(.:format) tags#show
PATCH /albums/:album_id/tags/:id(.:format) tags#update
PUT /albums/:album_id/tags/:id(.:format) tags#update
DELETE /albums/:album_id/tags/:id(.:format) tags#destroy
albums GET /albums(.:format) albums#index
POST /albums(.:format) albums#create
new_album GET /albums/new(.:format) albums#new
edit_album GET /albums/:id/edit(.:format) albums#edit
album GET /albums/:id(.:format) albums#show
PATCH /albums/:id(.:format) albums#update
PUT /albums/:id(.:format) albums#update
DELETE /albums/:id(.:format) albums#destroy
rails_postmark_inbound_emails POST /rails/action_mailbox/postmark/inbound_emails(.:format) action_mailbox/ingresses/postmark/inbound_emails#create
rails_relay_inbound_emails POST /rails/action_mailbox/relay/inbound_emails(.:format) action_mailbox/ingresses/relay/inbound_emails#create
rails_sendgrid_inbound_emails POST /rails/action_mailbox/sendgrid/inbound_emails(.:format) action_mailbox/ingresses/sendgrid/inbound_emails#create
rails_mandrill_inbound_health_check GET /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#health_check
rails_mandrill_inbound_emails POST /rails/action_mailbox/mandrill/inbound_emails(.:format) action_mailbox/ingresses/mandrill/inbound_emails#create
rails_mailgun_inbound_emails POST /rails/action_mailbox/mailgun/inbound_emails/mime(.:format) action_mailbox/ingresses/mailgun/inbound_emails#create
rails_conductor_inbound_emails GET /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#index
POST /rails/conductor/action_mailbox/inbound_emails(.:format) rails/conductor/action_mailbox/inbound_emails#create
new_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/new(.:format) rails/conductor/action_mailbox/inbound_emails#new
edit_rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id/edit(.:format) rails/conductor/action_mailbox/inbound_emails#edit
rails_conductor_inbound_email GET /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#show
PATCH /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update
PUT /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#update
DELETE /rails/conductor/action_mailbox/inbound_emails/:id(.:format) rails/conductor/action_mailbox/inbound_emails#destroy
new_rails_conductor_inbound_email_source GET /rails/conductor/action_mailbox/inbound_emails/sources/new(.:format) rails/conductor/action_mailbox/inbound_emails/sources#new
rails_conductor_inbound_email_sources POST /rails/conductor/action_mailbox/inbound_emails/sources(.:format) rails/conductor/action_mailbox/inbound_emails/sources#create
rails_conductor_inbound_email_reroute POST /rails/conductor/action_mailbox/:inbound_email_id/reroute(.:format) rails/conductor/action_mailbox/reroutes#create
rails_service_blob GET /rails/active_storage/blobs/redirect/:signed_id/*filename(.:format) active_storage/blobs/redirect#show
rails_service_blob_proxy GET /rails/active_storage/blobs/proxy/:signed_id/*filename(.:format) active_storage/blobs/proxy#show
GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs/redirect#show
rails_blob_representation GET /rails/active_storage/representations/redirect/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show
rails_blob_representation_proxy GET /rails/active_storage/representations/proxy/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/proxy#show
GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations/redirect#show
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
My Tags Controller:
class TagsController < ApplicationController
def create
#image = ActiveStorage::Blob.find(params[:image_id])
tags = params[:tag_name]
tags.each do |tag|
image = params[:image_id]
#tag = Tag.create(tag_name:tag,image_id:image)
redirect_to album_path(#album)
end
end
end
My Tag model:
class Tag < ApplicationRecord
belongs_to :image
end
and this is my show page(well half of it) in which error is coming:
<%= form_for(#tag, url: album_tags_path(#album) ) do |form|%>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Enter Tags for your Image here</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="tag-container d-flex flex-wrap">
<input class="form-control py-4 px-3" />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<%= form.submit class:"btn btn-info"%>
</div>
</div>
</div>
</div>
<% end %>
what is wrong in form_for url here???
I am getting error
ArgumentError in Albums#show
How about letting Rails deduce the route
<%= form_for([#album , #tag]) do |form| %>

Nested routes with polymorphic association

I'm trying to implement the act_as_votable gem in my rails application. I got it to work on the blogs model, but the comments model is where I'm stuck. I get undefined methodlike_comment_path'` when I try to run it, and it's because there are no routes being generated like there are for the blog.
Here is the routes file:
resources :blogs do
member do
put 'like', to: 'blogs#upvote'
put 'dislike', to: 'blogs#downvote'
end
resources :comments
member do
put 'like', to: 'comments#upvote'
put 'dislike', to: 'comments#downvote'
end
end
On the blog index, I am able to call the blog like path just fine.
<div class="btn-group">
<%= link_to like_blog_path(blog), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-up"></span>
Upvote
<%= blog.get_upvotes.size %>
<% end %>
<%= link_to dislike_blog_path(blog), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-down"></span>
Downvote
<%= blog.get_downvotes.size %>
<% end %>
</div>
I run into trouble, though, with the comment part.
<div class="btn-group">
<%= link_to like_comment_path(#commentable, comment), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-up"></span>
Upvote
<%= comment.get_upvotes.size %>
<% end %>
<%= link_to dislike_comment_path(#commentable, comment), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-down"></span>
Downvote
<%= comment.get_downvotes.size %>
<% end %>
</div>
When I run rake routes, nothing for the comments comes up.
Prefix Verb URI Pattern Controller#Action
root GET / glips#index
pages_home GET /pages/home(.:format) pages#home
pages_about GET /pages/about(.:format) pages#about
pages_contact GET /pages/contact(.:format) pages#contact
tag GET /tags/:tag(.:format) glips#index
new_user_session GET /login(.:format) devise/sessions#new
user_session POST /login(.:format) devise/sessions#create
destroy_user_session DELETE /logout(.:format) devise/sessions#destroy
new_user_password GET /password/new(.:format) devise/passwords#new
edit_user_password GET /password/edit(.:format) devise/passwords#edit
user_password PATCH /password(.:format) devise/passwords#update
PUT /password(.:format) devise/passwords#update
POST /password(.:format) devise/passwords#create
cancel_user_registration GET /cancel(.:format) devise/registrations#cancel
new_user_registration GET /register(.:format) devise/registrations#new
edit_user_registration GET /edit(.:format) devise/registrations#edit
user_registration PATCH / devise/registrations#update
PUT / devise/registrations#update
DELETE / devise/registrations#destroy
POST / devise/registrations#create
like_blog PUT /blogs/:id/like(.:format) blogs#upvote
dislike_blog PUT /blogs/:id/dislike(.:format) blogs#downvote
blog_comments GET /blogs/:blog_id/comments(.:format) comments#index
POST /blogs/:blog_id/comments(.:format) comments#create
new_blog_comment GET /blogs/:blog_id/comments/new(.:format) comments#new
edit_blog_comment GET /blogs/:blog_id/comments/:id/edit(.:format) comments#edit
blog_comment GET /blogs/:blog_id/comments/:id(.:format) comments#show
PATCH /blogs/:blog_id/comments/:id(.:format) comments#update
PUT /blogs/:blog_id/comments/:id(.:format) comments#update
DELETE /blogs/:blog_id/comments/:id(.:format) comments#destroy
PUT /blogs/:id/like(.:format) comments#upvote
PUT /blogs/:id/dislike(.:format) comments#downvote
blogs GET /blogs(.:format) blogs#index
POST /blogs(.:format) blogs#create
new_blog GET /blogs/new(.:format) blogs#new
edit_blog GET /blogs/:id/edit(.:format) blogs#edit
blog GET /blogs/:id(.:format) blogs#show
PATCH /blogs/:id(.:format) blogs#update
PUT /blogs/:id(.:format) blogs#update
DELETE /blogs/:id(.:format) blogs#destroy
users GET /users(.:format) users#index
GET /users/:id(.:format) users#show
user GET /users/:id(.:format) users#show
I cannot figure out how to make the comment path work with the routes. What am I doing wrong?
Are you looking for nesting the :comments resource inside :blogs? Otherwise your routes should look like:
resources :blogs do
member do
put 'like', to: 'blogs#upvote'
put 'dislike', to: 'blogs#downvote'
end
end
resources :comments do
member do
put 'like', to: 'comments#upvote'
put 'dislike', to: 'comments#downvote'
end
end
(note you had a missing do at beginning of the :comments block which resulted in a weird block ending/nesting)

Rails Devise Engine Sign_out link Error

I've installed devise on my engine and applied the following in my application.html.erb file:
<div id="user_nav">
<% if user_signed_in? %>
Signed in as <%= current_user.email %>. This cannot be cheese?
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %>
<% else %>
<%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %>
<% end %>
</div>
It shows No route matches "/users/sign_out" and it shows error for
<%= link_to 'Register', new_user_registration_path %> or <%= link_to 'Sign in', new_user_session_path %>
Error Message NameError in Devise::Sessions#new
undefined local variable or method `destroy_user_session_path' for #<#<Class:0x007fb4da2e9618>:0x007fb4da2db9a0>
Rake Routes Result
Routes for Fd::Engine:
users_auth_google_oauth2_callback GET /users/auth/google_oauth2/callback(.:format) fd/omniauth_callbacks#google_oauth2
fd_test_index GET /fd/test/index(.:format) fd/fd/test#index
fd_omniauth_callbacks_google_oauth2 GET /fd/omniauth_callbacks/google_oauth2(.:format) fd/fd/omniauth_callbacks#google_oauth2
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_omniauth_authorize GET|POST /users/auth/:provider(.:format) omniauth_callbacks#passthru {:provider=>/google_oauth2/}
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format) omniauth_callbacks#(?-mix:google_oauth2)
fd_auth_index GET /fd/auth/index(.:format) fd/fd/auth#index
root GET / fd/auth#index
omniauth_callbacks_verify_otp GET /omniauth_callbacks/verify_otp(.:format) fd/omniauth_callbacks#verify_otp
omniauth_callbacks_delete_session GET /omniauth_callbacks/delete_session(.:format) fd/omniauth_callbacks#sign_out
Engine routes:
Fd::Engine.routes.draw do
devise_for :users,:controllers => { :omniauth_callbacks => "omniauth_callbacks" }, :class_name => "Fd::User", module: :devise
end
You Integrated OmniAuth in Devise, so if user gives correct credentials devise will create session , From your question i understand session is successfully created so if you want clear session just create a action in a controller(where you start session) and give
redirect_to "/users/sign_out"
or
try
redirect_to destroy_user_session_path
I hope this will work
Try this :
<%= link_to "Sign out", destroy_user_session_path, :method => :get %>
And make sure that you have below line in your config/initializers/devise.rb
config.sign_out_via = :get

What route to use to link to resource creator?

My goal is to link the <%= #thing.user.username %> to the user's profile. I know it's something like:
<%= link_to #thing.user.username, %>
But what goes after the comma?
I can currently navigate to a user by going to "localhost:3000/users/UserNameHere". How do I link to that page dynamically?
Each of my Things has a line showing what user posted it. Here is how Things are displayed:
<div class='row'>
<div class='col-md-offset-2 col-md-8'>
<div class='panel panel-default'>
<div class='panel-heading text-center'>
<%= image_tag #thing.image.url(:medium) %>
</div>
<div class='panel-body'>
<p>
<strong><%= #thing.title %></strong>
</p>
<p>
<%= #thing.description %>
</p>
<p>
<%= #thing.user.username %>
</p>
<% if #thing.user == current_user %>
<%= link_to edit_thing_path(#thing) do %>
<span class='glyphicon glyphicon-edit'></span>
<% end %>
<% end %>
</div>
</div>
</div>
Here is my UsersController:
class UsersController < ApplicationController
def show
#user = User.find_by_id(params[:id])
end
end
Here are my routes:
Stynyl::Application.routes.draw do
resources :things
devise_for :users
get '/about', to: 'pages#about'
root 'things#index'
get 'users/:username' => "users#show"
end
Here is my rake routes output:
Prefix Verb URI Pattern Controller#Action
things GET /things(.:format) things#index
POST /things(.:format) things#create
new_thing GET /things/new(.:format) things#new
edit_thing GET /things/:id/edit(.:format) things#edit
thing GET /things/:id(.:format) things#show
PATCH /things/:id(.:format) things#update
PUT /things/:id(.:format) things#update
DELETE /things/:id(.:format) things#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
about GET /about(.:format) pages#about
root GET / things#index
GET /users/:username(.:format) users#show
You should stick to REST conventions in Rails, so use resources.
Replace:
get 'users/:username' => "users#show"
with:
resources :users, only: [:show]
then:
<%= link_to #thing.user.username, user_path(#thing.user.username) %>
or:
<%= link_to #thing.user.username, #thing.user %>
#and in model
def to_param
username
end
And replace params[:username] with params[:id] in your action.

Rails correct way to use link_to with devise

I'm getting started with rails and devise for authentication and I want to make a link to sign out when a user is logged into the admin page.
What is the correct way to write the link_to code
Here's my rake routes:
admin_index /admin/index(.:format) {:controller=>"admin/home", :action=>"index"}
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
home_index GET /home/index(.:format) {:controller=>"home", :action=>"index"}
root / {:controller=>"home", :action=>"index"}
I tried <%= link_to "Sign Out", destroy_user_session_path %> but when i click the link it gives me the error:
No route matches [GET] "/users/sign_out"
From this devise sample application, recommended on the Devise wiki:
<% if user_signed_in? %>
<li><%= link_to 'Edit account', edit_user_registration_path %></li>
<li><%= link_to 'Sign out', destroy_user_session_path, :method=>'delete' %></li>
<% end %>
the root error of your problem is that you haven't use RESTful routes in your "link_to".
you should correct your code to:
<%= link_to "Sign Out", destroy_user_session_path, :method => :delete %>
so that it will match the routes
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations" }

Resources