forms - Ruby on Rails POST request fails -
here thing goes, wanna write login in page in ruby on rails, when url localhost:3000/admin
, i'll page need fill in. after form has filled in, submit button , form should admitted create
action post
method, still works get
method , new
action.
what happens it?
here routes.rb
file:
prefix verb uri pattern controller#action new_admin_users /admin/users/new(.:format) admin/users#new admin_users post /admin/users(.:format) admin/users#create admin /admin(.:format) admin/users#new post /admin(.:format) admin/users#create posts_home /posts/home(.:format) redirect(301, /posts) posts_about /posts/about(.:format) redirect(301, /about)
then here new action
<form class="form-signin"> <h2 class="form-signin-heading">please sign in</h2> <%= form_for :user,url:admin_users_path |f| %> <p> <%= f.label :name%><br> <%= f.text_field :name ,class:"form-control" %> </p> <p> <%= f.label :pass%><br> <%= f.text_field :pass,class:"form-control" %> </p> <div class="checkbox"> <label> <input type="checkbox" value="remember-me"> remember me </label> </div> <p> <%= f.submit'sign in', :class=>"btn btn-lg btn-primary btn-block" %> </p> <%= link_to 'back', posts_path %> <%end%> </form>
here routes.rb
:
rails.application.routes.draw namespace :admin resources :users "", to:"users#new" post "", to:"users#create" end "/posts/home", to: redirect("/posts") "/posts/about", to: redirect("/about") resources :posts resources :comments end root "posts#index" "/home",to: "posts#index" "/about",to: "posts#about" end
if have throught, please tell me, in advance!
you must have actual user
object built inside controller. try using inside form instead of symbol :user
.
<%= form_for @user, url: admin_users_path |f| %> ...
Comments
Post a Comment