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 734867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:25:21+00:00 2026-05-14T07:25:21+00:00

I have an entries controller that allows users to add contact information the website.

  • 0

I have an entries controller that allows users to add contact information the website. The user-submitted information isn’t visible to users until the administrator checks a check box and submits the form. So basically my problem is that if I check the check box as an administrator while initially creating an entry (entries#new) the entry will be publicly visible as expected, but if a non-admin user creates an entry (the normal user view doesn’t include the ‘live’ check box, only the admin one does) then that entry is stuck in limbo because the entries#edit view for some reason doesn’t update the boolean check box value when logged in as an admin.

entries#new view:

<% form_for(@entry) do |f| %>
  <%= f.error_messages %>
  Name<br />
  <%= f.text_field :name %>

  Mailing Address<br />
  <%= f.text_field :address %>

  #...
  <%- if current_user -%>
    <%= f.label :live %><br />
    <%= f.check_box :live %>
  <%- end -%>
  <%= f.submit 'Create' %>
<% end %>

entries#edit (only accessible by admin) view:

<% form_for(@entry) do |f| %>
  <%= f.error_messages %>

  <%= f.label :name %><br />
  <%= f.text_field :name %>

  Mailing Address<br />
  <%= f.text_field :address %>

  <%= f.label :live %><br />
  <%= f.check_box :live %>

  <%= f.submit 'Update' %>

<% end %>

EDIT:

entries_controller.rb update method:

def update
  @entry = Entry.find(params[:id])
  respond_to do |format|
    if @entry.update_attributes(params[:entry])
      flash[:notice] = 'Entry was updated.'
      format.html { redirect_to(@entry) }
    else
      format.html { render :action => "edit" }
    end
  end
end

entry.rb:

class Entry < ActiveRecord::Base
  acts_as_mappable
  acts_as_taggable_on   :tags
  validates_presence_of :name, :tag_list
  validates_length_of   :name, :maximum => 64
  validates_length_of   :tag_list, :maximum => 128, :allow_blank => false
  validates_length_of   :paddress, :maximum => 128, :allow_blank => true
  validates_length_of   :address, :maximum => 128, :allow_blank => true
  validates_length_of   :tollfreephone, :in => 7..32, :allow_blank => true
  validates_length_of   :phone, :in => 7..32, :allow_blank => true
  validates_length_of   :phone2, :in => 7..32, :allow_blank => true
  validates_length_of   :mobile, :in => 7..32, :allow_blank => true
  validates_length_of   :fax, :in => 7..32, :allow_blank => true
  validates_length_of   :email, :in => 7..48, :allow_blank => true
  validates_format_of   :email,
                    :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i,
                    :on => :create, :allow_blank => true

  validates_length_of   :website, :maximum => 64, :allow_blank => true
  validates_length_of   :description, :maximum => 1024, :allow_blank => true
  attr_accessible       :name, :tag_list, :paddress, :address, :tollfreephone,
                        :phone, :phone2, :mobile, :fax, :email, :website,
                        :description 
  validate              :required_info
  before_save           :geocode_paddress
  searchable_on         :name, :address, :phone, :phone2, :mobile, :fax, :email,
                    :website, :category, :description
private
  def required_info
    if( phone.empty?  and phone2.empty? and tollfreephone.empty? and 
        mobile.empty? and fax.empty?    and email.empty?         and 
        website.empty? 
      ) 
      errors.add_to_base "Please have at least one form of contact information."
    end
  end
  def geocode_paddress
    # if paddress is nil or empty set the old values to nil and return    
    ((self.lat = self.lng = nil); return true) if paddress.empty?
    g=Geokit::Geocoders::MultiGeocoder.geocode(paddress)
    (errors.add(:paddress,"Could not Geocode address");
       return false) unless g.success
    self.lat, self.lng = g.lat, g.lng
  end
end

Any ideas as to why an administrator can’t update the :live check box from the edit view?

I would greatly appreciate any suggestions. I’m new to rails. I can post more code if it’s needed. Thanks for reading my question.

  • 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-05-14T07:25:22+00:00Added an answer on May 14, 2026 at 7:25 am

    You’re having an attr_accessible call

    attr_accessible       :name, :tag_list, :paddress, :address, :tollfreephone,
                        :phone, :phone2, :mobile, :fax, :email, :website,
                        :description 
    

    Which is great as it’ll avoid users to update other fields than the ones you allow them to.
    But your live field isn’t in there.

    So it’s value is filtered by rails as the user isn’t allow to update that field. Add it to the fields in the attr_accessible call and you’ll be able to edit it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with 50 entries (users with such details like Name Surname Location
I have a list of timesheet entries that show a start and stop time.
I have a table of transactions which will occasionally have duplicate entries. If/When an
I have a small database and have been adding entries through a Rails page.
I have an iterable of entries on which I would like to gather some
I have a simple database table called Entries: class CreateEntries < ActiveRecord::Migration def self.up
I have code similar to this filtering entries in an Array of Objects: var
I have a table containing hundreds of entries and I am trying to delete
I have an array of 1000 or so entries, with examples below: wickedweather liquidweather
I have a HashMap with millions of entries. Need to retrieve all entries whose

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.