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

  • Home
  • SEARCH
  • 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 7129635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:15:49+00:00 2026-05-28T11:15:49+00:00

I have this Pin Model: class Pin < ActiveRecord::Base belongs_to :user belongs_to :image accepts_nested_attributes_for

  • 0

I have this Pin Model:

class Pin < ActiveRecord::Base
  belongs_to :user
  belongs_to :image
  accepts_nested_attributes_for :image
  attr_accessible :image_attributes
end

I have this Image Model:

class Image < ActiveRecord::Base
  has_many :pins
   validates_attachment_presence :attachment
   validates_attachment_size :attachment, :less_than => 5.megabytes
   validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png']
   accepts_nested_attributes_for :pins
   attr_accessible :pins_attributes
end

For creating a New Pin I want to use nested attributes for image but its not working: Code I am using in controller and view file are:

def new
    @pin = Pin.new
    @pin.build_image if @pin.build_image.nil?
end

 def create
  @pin = Pin.new(params[:pin])
   @pin.user_id  = session[:user_id]
  respond_to do |format|
    if @pin.save
      format.html { redirect_to(@pin, :notice => 'Pin was successfully created.') }
      format.xml  { render :xml => @pin, :status => :created, :location => @pin }
    else
      @boards = User.find(session[:user_id]).boards
      format.html { render :action => "new" }
      format.xml  { render :xml => @pin.errors, :status => :unprocessable_entity }
    end
  end
end

And In view file:

   <%= form_for @pin,:html=>{ :multipart => true} do |f| %>
    <% if @pin.errors.any? %>
    <div id="error_explanation">
        <h2><%= pluralize(@pin.errors.count, "error") %> prohibited this pin from being saved:</h2>

        <ul>
            <% @pin.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
            <% end %>
        </ul>
    </div>
    <% end %>



    <div class="field">
        <%= f.label :title %>
        <%= f.text_area :title %>
    </div>
    <%= f.fields_for :image do |f_i| %>
    <div class="field">
        <%= f_i.label :attachment %>
        <%= f_i.file_field :attachment %>
    </div>
    <% end %>
    <div class="actions">
        <%= f.submit %>
    </div>
    <% end %>

All the time form is rendering an error:

     Image attachment file name must be set.
  • 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-28T11:15:49+00:00Added an answer on May 28, 2026 at 11:15 am

    In Image model I need to specify

      has_attached_file :attachment, :styles => { :small => "150x150>" }
    

    my bad 🙁

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

Sidebar

Related Questions

Have a class definition that looks something like this class someClass(models.Model): field1 = models.ForeignKey('other_app.field4')
In my model I have Address as a base class and MailingAddress , Email
I have three models: category.rb class Category include Mongoid::Document # Relationships has_many :posts, :autosave
I have a model class Place, which has a field for state, and I
I have a class model designed for a person class in python. where a
Been Facing this issue,I Have as my view <%= form_for(:pin, :url => {:action =>fees})
Let's say I have this code: class Score { public Update(int score) { update
i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from
I have a User class that has many posts and the post class has
Well I have this: Board: public class Board { public int BoardID { get;

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.