В моем приложении Ruby on Rails я сделал это так, чтобы пользователи могли зарегистрироваться, но как только сервер остановлен, и я снова загружаю страницу, они не вошли в систему (это нормально), но когда я нажимаю «Вход», я получаю следующее сообщение об ошибке:Ruby on Rails Почему я не могу войти?
NameError in Sessions#new
Showing C:/Sites/Thor/UnderConstruction/ThorCinema/app/views/sessions/new.html.erb where line #2 raised:
undefined local variable or method `sessions_create_path' for #<#<Class:0x6829bd8>:0x57ce460>
sessions_create_path
в просмотров/сессия/new.html.erb:
<div class="form1">
<%= form_tag sessions_create_path, :method => :get do %>
<fieldset>
<legend>Please Log In</legend>
<div>
<%= label_tag :name,'Name:' %>
<%= text_field_tag :name, params[:name] , :autofocus => true %>
</div>
<div>
<%= label_tag :password, 'Password:' %>
<%= password_field_tag :password, params[:password] %>
</div>
<div>
</br>
<%= submit_tag "Login" %>
</div>
</fieldset>
<% end %> <!-- form_tag -->
</br>
<%= link_to 'Back', :back %>
и sessions_controller создать метод:
def create
user = User.find_by name: params[:name]
if user and user.authenticate params[:password]
# 'logging in' is performed by saving a user's id in the session variable
session[:user_id] = user.id
# redirect to last page or root_path (products/index.html.erb')
redirect_to root_path
else
flash.now.alert = "Invalid user/password"
render :new
end
end
Кнопка Войти в application.html.erb:
<%= link_to "Log In", login_path %>
routes.rb:
controller :sessions do
get 'login' => :new
post 'login' => :create
get 'logout' => :destroy
end
resources :users
get 'films/index'
get 'categories/index'
get 'certificates/index'
resources :films
resources :categories
resources :certificates
resources :showings
root 'films#index'
post 'films/search', to: 'films#search'
post 'films/display_products_by_genre', :to => 'films#display_products_by_genre'
get 'films/display_products_by_genre', :to => 'films#display_products_by_genre'
post 'films/multi_find', :to => 'films#multi_find'
get 'films/multi_find', :to => 'films#multi_find'
match '*a', to: 'errors#routing', via: [:get, :post]
Может кто-нибудь сказать мне, почему журнал в не работает?
. Благодарим за сообщение, проблема заключается в том, что пользователь не входил в систему для выхода из системы, а при добавлении в этот код я получаю ошибку: 'undefined local variable or method destroy_user_session_path' –
Вы сохранили devise_for: users in ваши маршруты? – sansarp
Нет, у моих маршрутов нет, где это должно быть? –