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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:48:17+00:00 2026-05-26T11:48:17+00:00

(rails 2.2.2) I have 2 models, user and subscription. Each user can have one

  • 0

(rails 2.2.2)

I have 2 models, user and subscription. Each user can have one ore more subscriptions (= premium services). Below the attributes:

  • user: id, username, …
  • subscription: id, user_id (FK), type, started_at, ended_at

The classes:

class User < ActiveRecord::Base
  ..
  has_many :subscriptions, :dependent => :destroy
  ..
end

class Subscription < ActiveRecord::Base
  belongs_to :user, :foreign_key => :user_id
end

Now I want to make the UI part where existing users can subscribe in their account for the premium services. Therefore I wanted to make a first simple version where the user can subscribe by clicking on a checkbox. This is what I get so far

<div class = 'wrapper'>
  <%= render :partial => "my_account_leftbar" %>

  <% form_for @subscription, :url => subscribe_user_path(current_user) do |f| %>
  <div class="field">
    <%= (f.check_box :type?) %>      <!-- add '?'after the symbol, source: https://github.com/justinfrench/formtastic/issues/269 -->
  </div>

  <div class="actions">
    <%= f.submit "Subscribe", :class => "button mr8" %>
  </div>
  <% end %>
</div>

Problems:

  1. the app inserts a record into the db, but the attribute I defined in the form (type) has not been set (it should set ‘1’ which stands for ‘standard subscription’) . How to get the app set this attribute?
  2. how to set the FK? I assume that rails should set the FK automatically, is that assumption correct?
  3. how to set the other values ‘started_at’ and ‘ended_at? Those are datetime(timestamp) values…

Just run out of my beginner rails knowledge, any help really appreciated…

  • 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-26T11:48:18+00:00Added an answer on May 26, 2026 at 11:48 am

    ‘Type’ is a ruby on rails reserved word which should only be used when you are using Single Table Inheritance. You should rename your column name to something else.

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

Sidebar

Related Questions

I have three models: user, subscription, and channel. User: has_many :channels, :through => :subscriptions
I have the following models: class User < ActiveRecord::Base has_many :subscriptions end class Subscription
Rails 2.3.8. I have 3 models, User, Source, and Subscription. User attr_accessible :source_ids has_many
I have four rails models called user, school, subscription and news_item. I a situation
So I have two rails models - user and role - each specified with
I have those models User, Developer, App, Permission A User can have Default Permision
I have some rails app. For example I have next models: User , Post
I have a rails query like: @user = User.find_by_username(params[:search], :include => [:user_similars]) Models: user
In a Rails 3.2 app I have two user models set up using Devise:
I am developing a rails application in which I have two models User and

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.