How to use another page(not defaule) to edit user (Devise gem) ?
I have this situation: I need some page to add attributes to user, but I want to use edit_user_registration - I want to use another page.
So I need to create another action in registrations controller and add it in routes.rb. Also I created another file in registrations folder, but I have troubles with implementation.
Here is my registrations controller:
def paypal
end
and paypal.html.erb:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |d| %>
<%= d.email_field :paypal_email %>
...
<%end%>
Question: what I should write in my routes rb to call paypal action and edit page worked properly?
devise_for :users, :controllers => {:registrations => 'registrations', :sessions => 'sessions'} do
registrations#paypal//something here instead
end
Related
I have a settings tab which links to the user to edit_user_registrations_path corresponding to the devise/registrations/edit.html.erb page.
I created another page under devise/registrations called edit_account.html.erb and I'd like this to allow the user to edit additional settings like Twitter and any other social networks that allow it.
I keep getting a routing error. This is the route I tried using with no luck:
devise_scope :user do get "/edit/edit_account" => "devise/registrations#edit_account" end
Thanks in advance!
The way I do it in my routes file is like this:
devise_scope :user do
put "edit/edit_account", :to => "devise/registrations#edit_account",
:as => "edit_account"
end
and then like this:
<%= simple_form_for(resource, :as => resource_name, :url => edit_account_path(resource_name), :html => { :method => :put }) do |f| %>
I'm developing a rails app with a landingpage. On the landingpage, the user can sign up for the app. For login, there is an extra view with an extra controller.
It looks like this:
views/landinpage/index.html --> sign up form
views/login/index.html --> login form
but I only want to have one controller
controllers/login_controller --> create new user from sign up form & check login data
so I have to get a connection between the landingpage view and the login_controller.
This is my attempt:
<%= form_for #login, :url => { :controller => "login_controller", :action => "create" }, :html => {:method => :post} do |f| %>
but it throws a route error:
No route matches {:controller=>"login_controller", :action=>"create"}
I already defined login resources in routes.rb, but it seems that the problem is elsewhere?
resources :logins
any ideas?
try this
class LoginsController < ApplicationController
def new
...
end
def create
...
end
...
end
in your route.rb file write
match '/login/create' => 'logins#create', :as => :create_login
or
resources :logins
in your console - write - rake routes and check your routes
then
<%= form_for #login, :url => create_login_path(#login) do |f| %>
I think your code should look like this:
<%= form_for #login, :url => { :controller => "login", :action => "create" }, :html => {:method => :post} do |f| %>
can't test this right now, but I believe the _controller part is not required.
Update:
Another thing that I'm using a lot and that works:
<%= form_for #login, :url => create_login_path(#login), :html => {:method => :post} do |f| %>
You may have to fix the create_login_path part to match your application's routes but that's how I usually define these views.
Try this
class LoginsController < ApplicationController
def new
...
end
def create
...
end
...
end
in your routes.rb file
resources :logins do
collection do
post :create
end
end
and in your views
<%= form_for #login, :url => create_login_path(#login) do |f| %>>
you can see the html form action part, you can see!
your config/routes has
resources :posts
namespace :admin do
resources :posts
end
routes.rb:
devise_for :users, :controllers => {
:registrations => 'users',
:sessions => 'sessions',
:confirmations => 'confirmations',
:passwords => 'passwords'
}
The view for "edit" action:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= resource.inspect %>
resource.inspect shows all user's fields as nil.
Controller:
def edit
resource = params[:id].nil? ? current_user : User.find_by_id(params[:id])
end
What to put instead of "resource =" to make this thing work? I want that the view remains with default "resource" and "resource_name" variables.
IMPORTANT: I would prefer to retain the default behaviour for edit method without overriding it and without writing own code for it.
I am using devise for user registration but i am facing a problem where when i submit the signup form i get redirected to /users but i want to stay on /signup where the registration form is...
I achieved it but now i cant see any error messages
my starting form open code
<%= form_for(resource, :as => resource_name, :url => signup_path) do |f| %>
routes
devise_scope :user do
get "signup", :to => "devise/registrations#new"
post "signup", :to => "devise/registrations#new"
end
Your post route should point to "devise/registrations#create"
I have been working with rails3, here the view.html.erb form have one login button, so when i click on that button, gives no routes matches :controller => 'home', :action => 'login'. But i have put that in routes.rb. Why this happening?
view.html.erb
<%= form_tag( { :controller => 'home', :action => 'login' }, { :method
=> 'post'}) do %>
<%= text_field(:name, :name, :class => "span2",:placeholder =>
"Username") %>
<%= password_field_tag(:password, :password, :class =>"span2") %>
<%= submit_tag "Login", :class => "btn btn-primary" %>
<% end %>
**routes.rb**
resources :home
resources :home do
post :login, :on => :member
end
**homecontroller.rb**
class HomeController < ApplicationController
def login
end
end
You have defined "resources :home" twice, first declaration is useless and overrides second.
Since you used resources to define your routes (which is recomended) you should use the helper method generated, in this case its login_home_path instead of the old syntax { :controller => 'home', :action => 'login' }
First,
You declare resources :home two times.
try this way in your routes.rb
resources :home
match '/login', to: 'home#login'
and use login_path in submit tag.
I would prefere for login, logout, create Sessions controller
rails generate controller Sessions --no-test-framework
and for login create new method and for logout(signout) create destroy method