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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:06:10+00:00 2026-06-02T07:06:10+00:00

because I’m pretty new to Ruby on Rails I’ll explain what I did. I’ve

  • 0

because I’m pretty new to Ruby on Rails I’ll explain what I did. I’ve got a virtual attribute in my model called testing. I’ve defined it like this:

class Comment < ActiveRecord::Base
    attr_accessor :testing
    attr_accessible :user_name, :comment, :user, :testing

I then added custom method for custom validation like this:

validate :custom_validation

I also added the method, of course:

def custom_validation
   # a bit of custom_validation
end

I then added a field in my form:

<%= form_for(@comment) do |f| %>
    <%= render 'shared/error_messages', :object => f.object %>
    <%= f.hidden_field :post_id, :value => @post.id %>
    <% if !signed_in? %>
            <div class="field">
                    <%= f.label :user_name %>
                    <%= f.text_field :user_name, :class => "user_field" %>
            </div>
    <% else %>
            <%= f.hidden_field :user_id, :value => current_user.id %>
    <% end %>
            <div class="field">
                    <%= f.label :comment %>
                    <%= f.text_area :comment, :style => "height: 50px; width: 80%;" %>
            </div>
            <div class="field pin">
                    <%= f.label :testint %>
                    <%= f.text_field :testing, :class => "user_field" %>
            </div>
    <div class="buttons">
            <%= f.submit "Speichern" %>
    </div>
<% end %>

That’s all I did. So please don’t assume I did something else I didn’t describe here, because I didn’t 😉

My problem is, that my virtual field testing is always nil inside of my custom_validation method. Unless I run the validation in the console:

co = Comment.new
co.testing = "Hello"
co.valid?

I’ve checked using the logger. If I run via the console the testing-field isn’t nil. If I run it via the browser, it is. It seems that the parameter is somehow not passed to the model correctly. I hope I just missed something really obvious. Hope you can help me.

Cheers,
Michael

  • 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-02T07:06:11+00:00Added an answer on June 2, 2026 at 7:06 am

    It has to do with what’s in your create or update actions. The scaffold generator will put in code to set real attributes, but does not call setter methods from attr_accessor.

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

Sidebar

Related Questions

Because of the way in which YES/NO are defined, you cannot use YES/NO with
Because xlsx file may contain million rows, I decided to use poi event model,
Because of a bug with Float#round in Ruby 1.8.6, I was forced to upgrade
Because I'm currently setting up a new server for use, I've been using a
Because of the nature of new project we are about to start, I need
because I did something really bad in the past, I have to insert an
Because I've made .cpp files and then transferred them into .h files, the only
Because I've overloaded the operator++ for an iterator class template<typename T> typename list<T>::iterator& list<T>::iterator::operator++()
Because this is my first attempt at an extension method that seems quite useful
Because of transitive dependencies, my wars are getting populated by xml-apis, xerces jars. I

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.