[Rails] Re: Static Pages from Railcast
What i am doing wrong??
So I am at chapter 8, and everything seem to be working except that once
loggin I am apparently not login but do see some of the information such
as show correct user.
Here what I have
app/controllers/customers.rb
class CustomersController < ApplicationController
def show
@customer = Customer.find(params[:id])
end
def create
@customer = Customer.new(params[:customer])
if @customer.save
sign_in @customer
flash[:success] = "Welcome to Where you Where"
redirect_to @customer
# Handle a successful save.
else
render 'new'
end
end
def new
@customer = Customer.new
end
def edit
@customer = Customer.find(params[:id])
end
def update
if @customer.update_attributes(params[:customer])
flash[:success] = "Profile updated"
sign_in @customer
redirect_to @customer
else
render 'edit'
end
end
private
def signed_in_customer
redirect_to signin_path, notice: "Please sign in." unless
signed_in?
end
def correct_customer
@customer = Customer.find(params[:id])
redirect_to(root_path) unless current_customer?(@customer)
end
end
I have change the name of the resource from user to customer for trying
different then the person
this is my session help found in the folder
app/helpers/session.rb
module SessionsHelper
def sign_in(customer)
cookies.permanent[:remember_token] = customer.remember_token
self.current_customer= customer
end
def current_customer=(customer)
@current_customer = customer
end
def current_customer?(customer)
customer == current_customer
end
def current_customer
@current_customer ||=
Customer.find_by_remember_token(cookies[:remember_token])
end
def sign_in(customer)
cookies.permanent[:remember_token] = customer.remember_token
self.current_customer = customer
end
def signed_in?
!current_customer.nil?
end
def sign_out
cookies.delete(:remember_token)
self.current_customer = nil
end
end
Here his my header just in case i made a small mistake
<header class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<% if signed_in? %>
<li><%= link_to "Customers", '#' %></li>
<li id="fat-menu" class="dropdown">
<a href="#" class="dropdown-toggle"
data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_customer %></li>
<li><%= link_to "Settings", '#' %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: "delete"
%>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</div>
</div>
</header>
Again i only see sign and home as link has i am assuming something his
wrong with my sign process
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home