ruby on rails 4 - Error: no implicit conversion of Symbol into Intege -
i new ruby on rails , want create session each signed in user. error. in controller have :
class sessionscontroller < applicationcontroller def new end def create user =user.find_by pseudo :params[:pseudo] if user session[:user_id]=user.id flash[:notice]= "you signed in! " redirect root_url else flash.now[:alert]= "wrong password/pseudo" render 'new' end end def destroy session[:user_id]=nil flash[:notice]='you signed out' redirect root_url end end
in new.html.erb:
<h1>sessions#new</h1> <%= form_tag sessions_path %> <div> <%=label_tag 'pseudo', 'pseudo' %> <%= text_field_tag 'pseudo' %> </div> <div> <%= label_tag 'password', 'password' %> <%= password_field_tag 'password' %> </div> <%= submit_tag 'log in' %> <% end %>
and in index have :
<h1>users#index</h1> <% if current_user.present? %> welcome <%= current_user.pseudo %> | <%= link_to 'sign out' , logout_path %> <% else %> <%= link_to 'register', new_user_url %><br/> <%= link_to 'signin', login_path %> <% end %>
in application_controller.rb:
class applicationcontroller < actioncontroller::base # prevent csrf attacks raising exception. # apis, may want utilize :null_session instead. protect_from_forgery with: :exception helper_method :current_user private def current_user user.find_by id: session[:user_id] if session[:user_id] end end
and error related "user =user.find_by pseudo :params[:pseudo]" , did not understand why
ruby-on-rails-4
No comments:
Post a Comment