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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:43:20+00:00 2026-06-09T19:43:20+00:00

In the Rails 3 app I am working on, we allow users to activate

  • 0

In the Rails 3 app I am working on, we allow users to “activate” an account (by typing in a coupon code) and then they type in their information and voila, their account is created.

I am running into a small issue that I am unclear how to solve without duplicating code (that doesn’t seem eloquent).

Here is my current activations controller:

class ActivationsController < ApplicationController
  respond_to :html
  skip_before_filter :set_client, :only => [:welcome]

  def new
    @user = User.new
    @gc = get_group_code(params[:group_code])

    if @gc.nil? || @gc.group.school_info.blank?
      @countries = Country.all
      @school_types = SchoolType.all
      @states = State.all
    else
      @school_information = @gc.group.school_info
    end

    @user_type = UserType.find_by_type("Classroom Teacher")
  end

  def create
      @user = User.new(params[:user].except(:custom))

      if @user.save
        @group = Group.find(params[:group_id])
        @user.groups << @group
        @user.update_mail_chimp_sponsors
        UserMailer.welcome_email(@user, current_client).deliver
        sign_in @user
        redirect_to new_activation_welcome_path
      else
        render :new
      end
  end

  def welcome
    @user = current_user
  end

  private

    def get_group_code(code = "")
      group_code = GroupCode.find_by_code(code)

      unless group_code.nil?
        group_code.validate_code(current_client.name)
        group_code
      end
    end
end

The problem I am running into, is on line 31 (render :new). When there is an error with the form and the app renders the new method, instance variables from the new method are not available to the view. How can I solve this issue?

  • 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-09T19:43:21+00:00Added an answer on June 9, 2026 at 7:43 pm

    Render :new does exactly that: it renders the :new view. It does not execute the new method in the controller, so in what ever method you call render :new from you must set up the instance variables required by the :new template.

    It you do not want to duplicate code, you could move the setup of the instance variables to a private method in the controller. Then you can call the private method from the new method, and whatever other method from which you render :new.

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

Sidebar

Related Questions

I am working on a rails app that allows users to log in via
I'm working on creating a Rails app that allows users to set availability Sunday
I'm working on a Rails app that existing users can invite additional members to
I have a rails app I am working on that allows users to create
In my Rails app I would like to allow users to upload either image
I'm working to allow users to FB Connect into my app for authentcation. My
I'm working on Rails app with Paperclip gem used to save users' avatars. Production
I'm working on a Rails 3 app that allows users to follow movies by
A Rails app I'm working on will receive emails with attachments and then process
I have the following very ugly ruby code in a rails app I'm working

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.