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| %>
Related
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
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
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'm adding a nav menu in application.html.erb which navigate users in authlogic. All routers like: :logout, :register and :login seems working with custom paths.
match 'account/login' => 'user_sessions#new', :as => :login
match 'account/logout' => 'user_sessions#destroy', :as => :logout
match 'register' => 'users#new', :as => :register
Here is nav menu:
<% if current_user %>
<%= link_to "Edit Profile", edit_user_path(current_user.id)%> <%=h current_user.firstname %>
<%= link_to "Logout", :logout %>
<% else %>
<%= link_to "Register", :register %> |
<%= link_to "Login", :login %>
<% end %>
But edit_user_path is transferring me to /users/:id/edit. How do I make the nice URL for this path. I would like to make it /account/edit. It also need to disable this path /users/:id/edit to prevent user from requesting another user ID which doesnt belong to him/her. It should throw a 404 page is perfect.
Current paths in the nav menu:
Logout: /account/logout
Login: /account/login
Register: /register
I would love to have another path for edit_user_path:
Edit profile: /account/edit
Is there any way I can simply use edit_user_path(current_user.id) and the path automatically transfers me to /account/edit and disable id request.
Any help would be much appreciated! Thanks!
[Updated] This is my /config/router.rb
Appcatous::Application.routes.draw do
resources :users, :user_sessions
match "account" => "users#show", :as => :account
match 'account/login' => 'user_sessions#new', :as => :login
match 'account/logout' => 'user_sessions#destroy', :as => :logout
end
users.rb model is very simple:
class User < ActiveRecord::Base
acts_as_authentic
validates :firstname, :presence => true
validates :lastname, :presence => true
end
It would be helpful if you included all the routes in question - which means also the routes for the users. Did you create those with:
resources :users
In case you did, you'll have to disable that command and recreate just the routes you need manually with (example!):
match 'account/edit' => 'users#edit', :as => :edit_user
or whatever your controller is named. That way you'll get your "/account/edit" - however, you'll also have no way to transfer the user id that way. That one you'll have to transfer by other means, like through a variable stored in a cookie or a session.
The latter method is the usual way of remembering user authentification anyway.
I've followed a railscast on creating and displaying static pages using a pages model and my code looks like this:
Pages model
has fields of name, permalink and description.
Routes:
get "log_in" => "sessions#new", :as => "log_in"
get "log_out" => "sessions#destroy", :as => "log_out"
get "sign_up" => "users#new", :as => "sign_up"
root :to => "users#new"
resources :pages
match ':permalink', :controller => 'pages', :action => 'show'
_footer.html.erb
<div class="footer">
<div class="footer_container">
<%= link_to 'About Us', root_path('about') %>
</div>
</div>
going to /localhost:3000/about displays the about page correctly but the link in the footer wants to direct to /localhost:3000/.about and actually links to the sign up a new user page.
How can I get my link to direct to /about and display the page?
Thanks for any help its much appreciated!
root_path will always take you to users#new because that is what you specified in your routes.rb file. What you can do is name your last route with the :as key, like this:
match ':permalink', :controller => 'pages', :action => 'show', :as => 'my_page'
Then in your views, you should be able to do something like this:
<%= link_to 'About Us', my_page_path('about') %>