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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:24:59+00:00 2026-06-09T15:24:59+00:00

I have 2 controllers: DocumentsController and DashboardController After the user login successful, he is

  • 0

I have 2 controllers: DocumentsController and DashboardController
After the user login successful, he is redirected to dashboard_path, which has a form to create a ‘fast document’ like this

<%= form_for @document, :html => {:class => 'well'} do |f| %>
      <% if @document.errors.any? %>
        <div id="alert alert-block">
          <div class="alert alert-error">
          <h2>Couldn't create your doc. :(</h2>

          <ul>
          <% @document.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
          <% end %>
          </ul>
          </div>
        </div>
      <% end %>
      <label>A lot of fields</label>
      <%= f.text_field :fields %>

      <div class="form-actions">
        <%= f.submit 'Create document', :class => 'btn btn-large' %>
      </div>
    <% end %>

but when an exception happen (like the user forgot to fill a field), I would like to show these exceptions, not just an alert saying ‘Error’…actually, I didn’t found a way to do this

here’s my DashboarController

class DashboardController < ApplicationController
  before_filter :authenticate
  def index
    @document = Document.new
  end
end

and my DocumentsController

class DocumentsController < ApplicationController
  respond_to :json, :html
  def show

  end

  def create
    @document = Document.new(params[:document])
    @document.user = current_user

    if @document.save
      redirect_to dashboard_path, notice: 'Created!'
    else
      flash[:error] = 'Error!'
      redirect_to dashboard_path
    end
  end

end

any help is 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-06-09T15:25:00+00:00Added an answer on June 9, 2026 at 3:25 pm

    You are correctly redirecting on success; on failure, though, should not redirect; you need to render the template where the form was filled.

    if @document.save
      redirect_to dashboard_path, notice: 'Created!'
    else
      render 'dashboard/index'
    end
    

    You’ll have to make sure that any variables needed by the index template are available in the create action of the documents_controller (you’re just rendering the index template; you’re not running the code from the dashboard controller’s index action). Here’s a excerpt from the relevant Rails Guide to clarify:

    Using render with :action is a frequent source of confusion for Rails newcomers. The specified action is used to determine which view to render, but Rails does not run any of the code for that action in the controller. Any instance variables that you require in the view must be set up in the current action before calling render.

    More at http://guides.rubyonrails.org/layouts_and_rendering.html#using-render

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

Sidebar

Related Questions

I have 2 controllers, task and user. I need to create a view for
I have two controllers Project and Tag, both of which have a create view
i have several controllers which will all be using common functionality. So i have
I have many controllers that will have some similar behavior, e.g. the user should
I have two view controllers in a tabbar which can both edit data. Therefore,
I have sets of controllers which are each used for each authorization type. For
I'd like to implement ASP.Net MVC application which could have controllers, views and content
I am currently building a game, where u have controllers which you can move
I have two controllers, user and module. By default the user controller is loaded
I have two controllers, orders and tasks - each order has many tasks. In

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.