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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:59:34+00:00 2026-06-13T20:59:34+00:00

I’m trying to save an image when adding a new Trip via an association.

  • 0

I’m trying to save an image when adding a new Trip via an association.

tripphoto.rb has a belongs_to :trip

and my trip.rb has a has_many :tripphotos. Furthermore the Carrierwave documentation requires a few more things like an uploader and such which I’ve set up correctly (It worked without the association!).

Along with it I’ve got mount_uploader :tripphoto, TripphotoUploader in my trip.rb and accepts_nested_attributes_for :tripphotos, allow_destroy: true to get my form working properly as such:

    <%= fields_for :tripphotos do |photo| %>
      Img <%= photo.file_field :filename %>
    <% end %>

Nonetheless I get the error undefined methodtripphoto_changed?’ for #`. A quick Google has no fitting result. Any advice?

P.S here’s my Tripphoto table:

class Tripphoto < ActiveRecord::Base {
    :id => :integer,
    :filename => :string,
    :trip_id => :integer,
    :created_at => :datetime,
    :updated_at => :datetime
}

Thanks in advance,

Edit: On request my Codes:

Trip.rb

class Trip < ActiveRecord::Base
  attr_accessible :description, :title, :user_id, 
  :triplocations_attributes, :photo, :category_ids, 
  :start_city, :tripphotos, :img_url, :thumb_url, :images,
  :tags_attributes

  # validates :title, :length => {:minimum => 3}
  # validates :description, :presence => true
  # validates_associated :tags


  has_many :triplocations, :dependent => :destroy
  has_many :tripphotos, :dependent => :destroy

  has_and_belongs_to_many :categories
  has_and_belongs_to_many :tags


  accepts_nested_attributes_for :triplocations, allow_destroy: true
  accepts_nested_attributes_for :tripphotos, allow_destroy: true
  accepts_nested_attributes_for :categories
  accepts_nested_attributes_for :tags


  mount_uploader :tripphoto, TripphotoUploader
end

Tripphoto.rb

class Tripphoto < ActiveRecord::Base
  attr_accessible :filename, :trip_id
  belongs_to :trip
end

The complete trip form

<%= form_for @trip, :html => {:multipart => true} do |a| %> 
    <%= a.label :title, "Routetitel" %>
    <%= a.text_field :title %>

    <%= a.label :description, "Omschrijving" %>
    <%= a.text_area :description %>

    <%= a.label :start_city, "Stad" %>
    <%= a.text_field :start_city, :id => "cityName" %>

    <% for category in Category.find(:all) %>
        <div>
          <%= check_box_tag "trip[category_ids][]", category.id, @trip.categories.include?(category) %>
          <%= category.name %>
        </div>
    <% end %>
    <%= a.fields_for :tags do |f| %>
        <p>
            <%= f.label :title, 'Steekwoorden:' %>
            <%= f.text_field :title %>
        </p> 
        <div id="inputFields"></div>

    <% end %>
    <div style="background: red;">
        <%= fields_for :tripphotos do |photo| %>
          Img <%= photo.file_field :filename %>
        <% end %>
    </div>


    <%= a.submit 'Verstuur' %>
<% end %>
  • 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-13T20:59:35+00:00Added an answer on June 13, 2026 at 8:59 pm

    Two problems here :

    • you should mount the uploader on the field that will store the file name, the filename field in the Tripphoto model in that case, and not the tripphoto association.
    • you forgot the a. in front of fields_for, see what you did for the tags
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.