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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:58:09+00:00 2026-06-03T22:58:09+00:00

I have a belonging model that allows user to post objects to be sold

  • 0

I have a belonging model that allows user to post objects to be sold or rented on my website. I recently changed the form, making it a multi-step form: a first form asks the name of the object and if the object is for sale or to rent, a second form ask for object’s details, with the fields depending on the user’s choice.

I am using is_taggable, with Rails 3.0.5, and my problem is that tag_list is never saved in the database since I switched to the multi-step form (all the other fields are saved correctly).

I followed Ryan Bates Rails cast #217.

Before, I was using: @belonging.tag_list = params[:belonging][:tag_list]

Since I went from multistep, I am using: @belonging.tag_list = session[:belonging_params][:tag_list]

I am a bit of a newbie in Rails, so there might be something obvious I am missing here. I spent the whole afternoon and evening trying to understand what is wrong, any help will therefore be appreciated!

Here are the ‘new’ and ‘create’ action of my controller:

class BelongingsController < ApplicationController
  before_filter :authenticate_user!, :except => [:index, :with_tag, :remove_tag]
  after_filter :update_tag_cloud, :only => [:create, :update]

  def new
    @title = "Insert a new product or service"
    @user = current_user
    session[:belonging_params] ||= {}
    session[:belonging_step] = nil
    @belonging = @user.belongings.new(session[:belonging_params])
    session[:belonging_params][:tag_list] ||= []
    @belonging.current_step = session[:belonging_step]
    render 'new'
  end

  def create
    session[:belonging_params].deep_merge!(params[:belonging]) if params[:belonging]
    @belonging = current_user.belongings.build(session[:belonging_params])
    @belonging.current_step = session[:belonging_step]
    @belonging.tag_list=session[:belonging_params][:tag_list]
    if params[:previous_button]
      @belonging.previous_step
      render 'new'
    elsif params[:cancel_button]
      session[:belonging_step] = session[:belonging_params] = nil
      redirect_to user_path(current_user)
    elsif params[:continue_button]
      if @belonging.last_step?
        if @belonging.save!
          expire_fragment('category_list')
          flash[:success] = "New product or service created!"
          session[:belonging_step] = session[:belonging_params] = nil
          redirect_to belonging_path(@belonging)
        else
          flash[:error] = "Object could not be saved"
          render 'new'
        end
      else
        @belonging.next_step
        render 'new'
      end
    else
      render 'new'
    end
    session[:belonging_step] = @belonging.current_step
  end

Many many thanks for any clue !!

  • 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-03T22:58:10+00:00Added an answer on June 3, 2026 at 10:58 pm

    I actually thought that:

    session[:belonging_params].deep_merge!(params[:belonging]) if params[:belonging]
    

    would copy everything inside params[:belonging] but it seems that params[:belonging][:tag_list] was not copied into session[:belonging_params][:tag_list] as I expected …

    So the problem was solved by adding in the ‘create’ action a new session variable:

    session[:tag_list] = params[:belonging][:tag_list] to be able to save :tag_list from a step of the form to the next.

    session[:tag_list] is defined first in the ‘new’ action as:

    session[:tag_list] ||= []
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model User, that has_many belongings (a belonging belongs_to a user). I
I have a Category and a Post model, with each Post belonging to a
I have a complex form for a model Schedule that belongs to a parent
I have a User and Company model. There are three possible roles that a
Say I have a post and category model, with each post belonging to a
I have 3 objects in my model thus: Customer 1-----* Region 1-----* Branch To
I'm working on a website that allows people who run bed and breakfast businesses
I am relatively new to Rails. I have a User model through Devise. I
I have a Slot model, belonging to the Configuration model as well as another
I've got a question about updating attributes. I have an user model and also

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.