SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Location
    Marin CA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Admin Only Access for Textile Edits.

    Easy Question:

    I have multiple pages which I want to have available for Textile edits via the admin user. I have a User table which has a admin: boolean column. I am trying to allow those who are admin (boolean = TRUE) to see the edit feature.

    In my views model, I have the following viewer code to let those who are logged in to see the edit feature:

    <% if logged_in? %>

    <a href='#' id='edit'>Edit This Page</a>

    <%= in_place_editor_field age, 'body', {},
    {:rows => 20, :cols => 80, :external_control => 'edit', :external_control_only => true,
    :load_text_url => {:controller => 'viewer', :action => 'get_unformatted_text', :id => @page.id}
    } %>

    <% else %>

    <%= @page.body %>

    <% end %>

    Now I simply want to change the If to only allow Users.admin access to the in_place_editor_field. Should be easy but I am having troubles.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,039
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    Did you try something like
    application.rb
    Code Ruby:
          helper_method :is_admin?
        def is_admin? 
            if logged_in? && current_user.login == "admin"
              true
            else
              false
            end
        end
    and
    edit.html.erb
    Code Ruby:
    <% if is_admin? %>

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    Did you try something like
    application.rb
    Code Ruby:
    helper_method :is_admin?
    Should "application.rb" be "application_helper.rb" ?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,039
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    I guess if you wanted or had to. I'm going by the only 2 tutorials I have that use helper methods. Both are in app/controllers/application.rb

  5. #5
    SitePoint Member
    Join Date
    Apr 2009
    Location
    Marin CA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the reply. I have tried your solution (as written) and by replacing
    current_user.login
    with: @user

    Either way I am getting a syntax error which looks like the following:

    syntax error, unexpected tANDOP
    if logged_in?? && @user == "admin"
    ^
    /Users/rubyadmin/rxPaleoZone/app/controllers/application_controller.rb:37: syntax error, unexpected kEND, expecting $end

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need a matching
    Code:
    <% end %>
    At the end of the block you are displaying if the user is admin. For example:
    Code:
    <% if logged_in? and @user == "admin" %>
    <p>You are logged on as admin</p>
    <% end %>

  7. #7
    SitePoint Member
    Join Date
    Apr 2009
    Location
    Marin CA
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YEP works perfectly. Many thanks for all of the support and help from this forum. I can't wait to get proficient enough to pay it forward to others.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •