similar to: Access instance variables from model?

Displaying 20 results from an estimated 3000 matches similar to: "Access instance variables from model?"

2009 Apr 29
7
problem with nil.user
Hi all, I''ve put new code into my app 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'')
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
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/> <%=
2008 Jan 21
7
undefined method error
Hello everyone, I am following the Practical Rails: Social Networking sites book. In chapter 7 photo gallery I 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:
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?
2006 Mar 02
8
User Authentication
I''m trying to create a simple authentication system but am failing miserably. I''m (sort of) following the "Logging In" chapter of the Agile book. Ideally, any access to http://example.com/publish (and any of its subdirectories) should redirect to http:/example.com/publish/login when there is no valid session user_id. Code so far:
2009 Feb 25
3
Secure but elegant destruction method
Hi,- I am looking for a clean and secure way for an ActiveRecord instance to delete itself. Say I have a User model in my app. Then the destructive action would be /users/user_id/destroy. If this action is not secured by a filter like: (*) before_filter :check_administrator_role, :only => :destroy then any user could potentially log in and start issuing: /users/1/destroy /users/2/destroy .
2006 Mar 21
5
Use select_date for my model?
Hi all I have a model "party" that has a time field "starts_at". I have created a form to add new instances of this model. <%= select_date Date.today, :prefix => ''party'' %> Sadly I get the error: NoMethodError in Parties#add undefined method `month='' for #<Party:0x256a600> How can I fix this problem? I remember that I saw in
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
2011 Aug 06
7
Accessing datetime elements from hash passed to method
I''m passing hash (called ''params'') to a method. Some keys (one of them is called ''starts_at'') in that hash have date as a value (taken from datetime_select helper). I want to access the date elements like date only or time only but I''m just out of ideas. def self.new_meeting(params) str = params[''starts_at(1i)'']
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&uuml;ltige Daten!" end end . . . end with this rjs template: login.rjs: if @logged_in_user
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 20
47
SQL Server datetime error
i have a problem with the datetime format of rails. i am unable to save a dataset to the db. here''s the error message -- the original error message was in german, so i translated it -- i get: DBI::DatabaseError: Execute OLE error code:80040E07 in Microsoft OLE DB Provider for SQL Server Couldn''t convert a char-Datatype to datetime HRESULT error code:0x80020009
2006 Jan 13
0
Layout not rendered when render_component used
Hi I''ve got a login action that handles authenticating users, setting cookies and, via its view, displaying an HTML snippet containing a form with username and password fields. It''s called from the main application.rhtml layout so I don''t need to have a seperate page (away from the main site) with a login form. My user model is more-or-less the same as in the Agile RoR
2009 Feb 21
1
undefined method user_id
Basically, Im trying to add comments to photos that other users have uploaded. And Ive encountered an error: NoMethodError in CommentsController#create undefined method `user_id='' for #<Comment:0x4768cd0> C:/INSTAN~1/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1857:in `method_missing''
2007 Jul 20
3
Mozzila Logout back button issue
Hello, I have recently created an application in Rails which makes use of a login and logout system. I have a user controller and model as well as a login controller. 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
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 May 04
22
Should controllers be "smart"?
I''m working on a small project with a friend, and one of the things we needed to do was send off an email whenever someone signs up an account. His implementation was pretty simple - throw a deliver_welcome call inside the controller after the signup. I''m sure that this is a pretty common thing to do. The problem, in my mind, was that the app now became tied to two places -