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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:47:47+00:00 2026-06-16T02:47:47+00:00

I haven’t had a problem with validations before but this time I am having

  • 0

I haven’t had a problem with validations before but this time I am having issues with nested_form validations. I am using Twitter Bootstrap and can get flash errors to show with, say, this:

 def create
 @recipe = current_user.recipes.new(params[:recipe])
 if @recipe.save
  redirect_to my_recipes_path, :notice => "Thanks #{current_user.name} Recipe sucessfully created."
  else
  render :action => 'new'
 end
end

For my flash messages I use this in my app/layouts

 <% flash.each do |name, msg| %>
 <div class="alert alert-<%= name == :notice ? "success" : "error" %>">
  <a class="close" data-dismiss="alert">×</a>
  <%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %>
 </div>
 <% end %>

So I thought I would try and just get one of the validators working, so my model

class Recipe < ActiveRecord::Base

belongs_to :user
delegate :name, :to => :user, :prefix => :user, :allow_nil => true
belongs_to :country
has_many :ingredients 
has_many :preperations
has_many :favourites

validates_presence_of :dish_name

and my form

    <%= nested_form_for @recipe  do |f| %>

    <div class="field_with_errors"> 
    <%= f.label :dish_name, "Dish Name" %>
    <%= f.text_field :dish_name, :placeholder => "Enter Dish Name" %>
    </div>


    <%= f.label :country_id, "Country Of Origin" %>
    <%= f.collection_select(:country_id, Country.all, :id, :name, :prompt => 'Please select country') %>

    <%= f.label :category, "Category" %>
    <%= f.select :category, [['Starter'], ['Main Course'], ['Desserts'],  ['Vegeterian']], {:include_blank => 'Please Select'} %>


   <%= f.label :difficulty, "Difficulty Level" %>
   <%= f.select :difficulty, [['Beginner'],['Intermediate'],['Expert']], {:include_blank => 'Please Select'} %>

   <%= f.label :preperation_time, "Preperation Time (Mins)" %>
   <%= f.select :preperation_time, [['15-30 Mins'],['30-60 Mins'],['60-120 Mins']], {:include_blank => 'Please Select'} %>

   <%= f.fields_for :ingredients do |ing| %>
   Ingredient<br>
   <%= ing.text_field :ingredient_name , :placeholder => "Enter Ingredient Here" %><br>
   <% end %>
   <%= f.link_to_add "Add an Ingredient", :ingredients %><br>

   <%= f.fields_for :preperations do |prep| %>
   Preperation Step<br>
   <%= prep.text_field :prep_steps , :placeholder => "Enter step Here" %><br>
   <% end %>

   <%= f.link_to_add "Add a step", :preperations %><br>

   <%= f.label :description, "Description of Recipe" %>
   <%= f.text_area :description, :size=> "60x10" %></br>

   <%= f.file_field :avatar %><br>

   <%= f.submit "Submit Recipe" %>
   <% end %>

I am fairly new to Rails so I may have missed something fundamental, or is it because it is a nested form and it behaves differently?

Edit

Output of <%= flash debug %>:

  --- !ruby/object:ActionDispatch::Flash::FlashHash
 used: !ruby/object:Set
 hash: {}
 closed: false
 flashes: {}
 now:
  • 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-16T02:47:48+00:00Added an answer on June 16, 2026 at 2:47 am

    It seems you’re not actually providing your flash hash with any messages to work with. A quick solution might be something like:

    def create
     @recipe = current_user.recipes.new(params[:recipe])
     if @recipe.save
       redirect_to my_recipes_path, :notice => "Thanks #{current_user.name} Recipe sucessfully created."
     else
       flash[:error] =  @recipe.errors.full_messages.to_sentence
       render :action => 'new'
     end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't used the STL much before, but I started to on this huffman
Haven't seen this before so hopefully someone has a easy solve, I have a
Haven't found anything useful about this on the internet. I'm using my Windows 7
I haven't been able to find much about this but am I the only
Haven't found a solution to this problem yet, have tried some things... I have
Haven't seen anything about it here but it seems to solve one of the
I haven't been able to get this working and all of the sample code
I haven't actually built an app yet, but I'm confused by documentation on bind-attr.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I haven't found information about this anywhere. Is there a minimal required length for

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.