Displaying 20 results from an estimated 22 matches for "logged_in_user".
2009 Apr 29
7
problem with nil.user
...p so that an administrator will have
extra privileges (administer users, edit pages). The error is:
''Couldn''t find User without an ID''
So the app is looking for a logged in user when the homepage is
accessed.
Heres my code:
site/index view:
<% if is_logged_in? and logged_in_user.has_role?(''Moderator'') -%>
<%= link_to ''Administer Users'', :controller => ''user'', :action =>
''show'' %>
<%= link_to '' | Edit pages'', pages_path %>
<% end %>
application h...
2009 Jun 05
6
rails 2.3.2
Hi all,
I am using rails v.2.3.2 and if I put following line to my
ApplicationController:
include LoginSystem
and I moved my login_system.rb to lib folder:
module LoginSystem
protected
def is_logged_in?
@logged_in_user = User.find(session[:user]) if session[:user]
end
def logged_in_user
return @logged_in_user if is_logged_in?
end
def logged_in_user=(user)
if !user.nil?
session[:user] = user.id
@logged_in_user = user
end
end
def self.included(base)
base.send :helper_metho...
2008 Jan 21
7
undefined method error
...am getting a
NoMethodError in Pages#show
Showing layouts/_menu.rhtml where line #12 raised:
undefined method `new_entry_path'' for #<ActionView::Base:0x52fa56c>
Extracted source (around line #12):
9: <% if is_logged_in? %>
10: <li>Logged in as: <i><%= logged_in_user.username %></i></li>
11: <li><%= link_to ''My Profile'', edit_user_path(logged_in_user)
%></li>
12: <li><%= link_to ''New Blog Post'', new_entry_path(:user_id =>
logged_in_user) -%></li>
13: <li>...
2006 Jul 27
2
setting initial text field values in a form
Hi,
I am trying to create a basic form in which I want one of the fields
initialized before displaying it.
My code (in a view) is as follows:
<%
if ( session[:user_id] != nil )
then
logged_in_user = User.find(session[:user_id])
end
%>
<% form_for :suggestion do |form| %>
<label for="suggestion_title">Topic:</label><br/>
<%= form.text_field :title, :size => 64 %>
<label for="suggestion_email">Email:</label><br/>
<...
2006 Jun 06
5
Functional tests and protected actions
Hello!
I have certain methods in my Application Controller, that I need to access.
Namely ApplicationController#logged_in_user
The problem is, that when I try to access it, I get:
NoMethodError: protected method `logged_in_user'' called for
#<AdminController>
Any ideas how I can circumvent that?
Or are functional tests really not suited for any kind of logins and session
work? I don''t see why I...
2006 Mar 02
8
User Authentication
.../example.com/publish/login when
there is no valid session user_id.
Code so far:
--------------------------------------------
# controller
class PublishController < ApplicationController
before_filter :authenticate, :except => [:login, :login_user]
def login
if request.post?
logged_in_user = @user.attempt_login
if logged_in_user
session[:user_id] = logged_in_user.id
redirect_to(:action => ''index'')
else
flash[:notice] = ''Invalid username or password. Please try again''
end
end
end
def...
2009 Feb 25
3
Secure but elegant destruction method
...ssuing:
/users/1/destroy
/users/2/destroy
.
.
.
/users/n/destroy
But I want to give a User the possibility to delete [him|her]self.
Currently the only way I can think of it is this:
1) Remove the filter (*)
2) Re-code the destroy method so:
def destroy
@user = User.find(params[:id])
if logged_in_user == @user or
logged_in_user.has_role?(''administrator'')
if @user.destroy
flash[:notice] = "User deleted"
else
flash[:error] = "There was a problem deleting this user."
end
redirect_to :action => ''index''
end
But,...
2006 Dec 01
3
Sessions in Layered Dispatching
Can you use sessions in layered dispatching? I used them in direct
dispatching without any problems, but switching to layered throws an
error (saying session doesn''t exist).
Sorry if this is a double post, Google Groups isn''t posting my message
for some reason.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this
2006 Jan 29
1
RJS template problem!
hi all,
i have the following controller:
class UserController < ApplicationController
.
.
.
def login
@user = User.new(params[:user])
@logged_in_user = @user.try_to_login
if @logged_in_user
session[:user_id] = @logged_in_user.id
else
flash[:notice] = "ungültige Daten!"
end
end
.
.
.
end
with this rjs template:
login.rjs:
if @logged_in_user
page.replace_html ''content'', ''welcome!'...
2006 Apr 07
2
Access instance variables from model?
Can I make my model methods aware of the context (preferably instance
variables) where they are run, without having to pass them arguments?
The app in question should be time zone aware, so something like
user.events[0].starts_in should check against @logged_in_user.now rather
than Time.now.
I could send the user as an argument
(user.events[0].starts_in(:timezoned => @logged_in_user)), but there are
a number of methods where this applies, and it seems more DRY to just
read it from the context.
I do realize this might not be ideal MVC, so I''m...
2006 Mar 16
4
Handling/Catching Exceptions
Hello!
I was wondering, sometimes I raise an exception in my Rails apps, e.g.:
raise SecurityError unless @post.user == logged_in_user
Now: is there any way to catch that SecurityError exception somewhere
and render a custom template? E.g., I want to render
''app/views/content/security_error.rhtml''
Does anyone know how to do this?
Thanks a bunch,
Rob
2006 Jan 01
4
Agile book deltas
Are there deltas for the revisions of the PDF version of the Agile book?
-- fxn
2009 May 20
3
ffmpeg + mp3 convert
Hi all,
I am using paperclip plugin to upload mp3''s. Before I save the mp3 I
would like to convert it to a smaller size.
I am using ffmpeg library and in my Track model I am calling:
before_save :convert_mp3
def convert_mp3
system("ffmpeg -i #{mp3.to_file.path} -vn -ar 44100 -ac 2 -ab 64 -f
mp3 #{mp3.to_file.path}")
end
But this fails. Am I missing something?
2006 Jan 13
0
Layout not rendered when render_component used
...te) with a login form.
My user model is more-or-less the same as in the Agile RoR book.
app/controllers/auth_controller.rb:
class AuthController < ApplicationController
layout false
def login
if request.get?
@user = User.new
else
@user = User.new(@params[:user])
logged_in_user = @user.try_to_login
if logged_in_user
# handle setting cookies, setting session
# and redirecting to index
else
flash[:loginerror] = ''Invalid username/password combination''
end
end
end
end
app/views/login.rhtml
<div id="lo...
2009 Feb 21
1
undefined method user_id
...ments controller:
class CommentsController < ApplicationController
before_filter :login_required
def create
@photo = Photo.find_by_user_id_and_id(params[:user_id],
params[:photo_id])
@comment = Comment.new(:user_id => @logged_in_user.id,
:body =>
params[:comment][:body])
if @photo.comments << @comment
flash[:notice] = ''Comment was successfully created.''
redirect_to photos_path(:user_id => @photo.user,...
2007 Jul 20
3
Mozzila Logout back button issue
...ler. My login controller performs my logout and login
functions. The user is a scaffold of my database table and is auto
generated from rails.
def process_login
#Creates the user with the form variables i have not included the
code
#here to create the user cause its not necessary
if logged_in_user
session[:user_id] = logged_in_user.id
flash[:notice] = ''You have been logged in.''
redirect_to(:controller => ''admin'', :action => "index")
else
flash[:notice] = ''Invalid user and or password combination''...
2006 Jun 13
13
Pass infomation between different views and controllers
Hi, I am a rails and ruby nuby :-)
How do you pass data between different controllers and views? I have a
page ( a quote) that I am editing url ....quote/edit/6 6 id the
current id. I then go to a catalog (url....catalog) to add an item to
my quote (I do this via a line_item file that the quote reads) I now
want to go back to the quote. I have tried this
<%= link_to ''Back to
2006 Apr 05
0
cookies not deleting?????
...nd "myapp.com". To fix this, when i set the cookie i
specified the domain to be ".myapp.com". However now when i try to delete
the cookie cookies.delete :myapp_cookie, it wont delete.
Why is that?
Here is my code:
when logging in -
...
cookies[:myapp_cookie] = {:value => logged_in_user.get_remember_token,
:expires => 1.year.from_now,
:domain => ''.myapp.com''}
...
when logging out -
...
cookies.delete :myapp_cookie
...
Any help would be greatly appreciated.
-------------- n...
2008 Jun 14
1
help with collection_select
Hi,
I have a table called ''users'', there is a field called ''username'' and
another field called ''mobile_number'' (among other fields).
In my application the user can send SMS message and can choose between
his/her username and mobile number as the sender id. Both of them are of
course stored in the users table. Also there is a third option which
2008 Mar 03
3
Admin and standard controllers RESTFully
Hello. I will appreciate the opinion.
What is the standard way of separating admin functions from normal-
user functions?
before_filter in one controller?
Use two controllers, i.e. ProductController and Admin/
ProductController?
I want to use map.resources so RESTFul would be better.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to