Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7930575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:28:13+00:00 2026-06-03T20:28:13+00:00

I’m currently working on a hobby project in Rails, and stumbled upon a what

  • 0

I’m currently working on a hobby project in Rails, and stumbled upon a what I will think is a common problem in Rails. I’ve been through a couple of chapters plus and a Lynda tutorial, but I haven’t found any best practices for this problem. Maybe the online community can help me.

In my application.html.erb I have added the following code:

<!DOCTYPE html>
<html> 
<head>
  <title>SioMeny</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
</head>
 <body>
  <div id="wrapper">
    <header>
      <h1>SiO Menysystem</h1>
    </header>
    <div id="site_menu">
       <%= render :partial => "shared/admin_menu" if admin_logged_in? %>
       <%= render :partial => "shared/user_menu" if logged_in? %>
       <%= render :partial => "shared/site_menu" %>
    </div><!-- div#site_menu -->
   <div id="main">
      <%= render :partial => "shared/flash", :locals => {:flash => flash} unless flash.nil? %>
      <%= yield %>
    </div>
  </div><!-- div#wrapper -->
</body>
</html>

My problem starts in the #site_menu and in the loading of the different partials. What I try to achieve here is a menu that is expanding according to the privileges a user may have. The logged_in? and the admin_logged_in? Is located in the application_controller.

class ApplicationController < ActionController::Base
  protect_from_forgery


  def login_required
    unless logged_in?
     flash[:notice] = "Du må være logget inn for å se denne siden"
     redirect_to :controller => "user", :action => "login"
   end
 end

   def admin_required
   unless admin_logged_in?
     flash[:notice] = "Du må være logget inn som administrator for å se denne siden"
     redirect_to :controller => "user", :action => "login"
   end
 end



  def logged_in? 
    if session[:user_id]
     return true
   end
    return false
 end

  def admin_logged_in? 
   if logged_in?
      user = User.find_by_id[:user_id]
     if user.is_admin?
       return true
     end
   end
   return false
  end


end

At this point I get an error:

ArgumentError in Site#index

Showing /Users/ola/Documents/Coding/SioMeny/app/views/layouts/application.html.erb where line #15 raised:

wrong number of arguments (0 for 1)
Extracted source (around line #15):

12:       <h1>SiO Menysystem</h1>
13:     </header>
14:     <div id="site_menu">
15:       <%= render :partial => "shared/admin_menu" if admin_logged_in? %>
16:       <%= render :partial => "shared/user_menu" if logged_in? %>
17:       <%= render :partial => "shared/site_menu" %>
18:     </div><!-- div#site_menu -->
Rails.root: /Users/ola/Documents/Coding/SioMeny

Any help is very welcome! I have also tried to get both the logged_in functions to set an instance variable which of type Boolean which is checked in the view, this worked, but not all the time since they were depending on when they were set. I also tried to make similar methods in a helper and call them from the view, but that didn’t work either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:28:15+00:00Added an answer on June 3, 2026 at 8:28 pm

    I think your problem is this line in admin_logged_in?

    user = User.find_by_id[:user_id]
    

    using the brackets at the end of find_by_id, doesn’t pass the symbol in as a parameter, it just directly calls find_by_id with no parameters. And find_by_id expects a parameter. Assuming you had a :user_id available in your params hash, you could do something like this instead:

    user = User.find_by_id(params[:user_id])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.