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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:54:07+00:00 2026-06-18T14:54:07+00:00

I have a controller in a rails app whereby a user can create a

  • 0

I have a controller in a rails app whereby a user can create a holiday request, it seems that when I fill out the necessary information it is not doing the POST request and submitting my form. My output in the RailsPanel follows: Rails Panel. From this its as if it is doing the GET request when surely on it should do a GET then a POST. I believe I have messed up somewhere around my create method. Any feedback would be great thank you!

controller

class HolidaysController < ApplicationController
  before_filter :authenticate_user!
  before_filter :admin_user, :only => [:index, :update, :edit, :absence]
  before_filter :correct_user, :only => [:delete]

  def new
    @holiday = Holiday.new
    @user = current_user
  end

  def show
    @holiday = Holiday.find(params[:id])
    c_u = current_user
  end

  def create
    @user = current_user
    @holiday = current.holidays.build(params[:holiday])
    @holiday.approver_id = approval_method(current_user, @holiday)
    if @holiday.save
      redirect_to root_path
      flash[:success]= "holiday application sent!"
    else
      render :new
    end
  end

  def myholidays
    @holidays = current_user.holidays.all
  end

  def index
    @holidays = Holiday.all
  end

  def absence
    #show the holidays where the approver id matches the current user id
    #and state = "requested"'

    @user = current_user
    if current_user.role? :administrator
      # a admin can view all current holiday requests
      @holidays = Holiday.all( :conditions => 'state = "requested"')
    else
    #otherwise an admin sees the holiday requests that they are approvers for
      @holidays = Holiday.all(:conditions => ["approver_id = #{current_user.id}", "state = requested"])
    end
  end

  def edit 
    today = Date.today
    @holidays = Holiday.all
    @month = (params[:month] || (Time.zone || Time).now.month).to_i
    @year = (params[:year] || (Time.zone || Time).now.year).to_i
    @shown_month = Date.civil(@year, @month)
    #L51 - Parses the given representation of date and time with the given template
    #and returns a hash of parsed elements.
    @holiday = Holiday.find(params[:id])
  end

 def update
   admin = User.find(current_user.role? :administrator)
   holiday = Holiday.find(params[:id])
   user = User.find(id = holiday.user_id)

   if holiday.update_attributes(params[:holiday])
     if holiday.state == "approved"
       user.absentdays = user.absentdays - (holiday.days_used).to_i
       user.save
     end
     redirect_to absence_path, :notice => "Request updated"
   else 
     render 'edit'
   end
 end

 def destroy 
   Holiday.find(params[:id]).destroy 
   redirect_to root_url, :notice => "Request deleted"
 end

 private 

 def current_user?(user)
   user == current_user
 end 

 def admin_user
   redirect_to dashboard_path, :notice => "You must be an admin to do this!" unless current_user.role? :administrator
 end

 def signed_in_user 
   redirect_to login_path, notice: "Please sign in." unless signed_in? 
 end

 def correct_user 
   @user = current_user 
   redirect_to dashboard, notice: "You are not the correct user." unless current_user?(@user) or current_user.role? :administrator
 end

 def approval_method(current_user, holiday_to_approve)
   found = false 
   days = holiday_to_approve.days_used
   user = current_user 
   approver = user.role? :administrator

   until found == true 
     #Admins should be automatically approved and have no approvers 
     if approver == nil 
       holiday_to_approve.state = "approved"
       #if user absent days is equal to absent days - day and convert to integer
       user.absentdays = user.absentdays - (days).to_i
       user.save

       found = true 
     else 
       redirect_to dashboard_path, :notice => "Request complete"
     end 
     break if found == true 
     end 
   end
end

holidays/show.html.erb

<form class="form">
<p>You have<b><%= @user.absentdays %> days of holiday left.</b></p>
<%= form_for @holiday do |f| %>
    <% if @holiday.errors.any? %>
        <div>
          <h2>Form is invalid</h2>
          <ul>
            <% for message in @holiday.error.full_messages %>
                <li><%= message %></li>
            <% end %>
          </ul>
        </div>
    <% end %>
    Select the dates required for absence<br>
    Start: <%= datepicker_input "holiday", "start_at", :minDate => 0, :dateFormat => "yy-mm-dd" %><br>
    End: <%= datepicker_input "holiday", "end_at", :minDate => 0, :dateFormat => "yy-mm-dd" %>

    <br><br>

    Please select the type of absence you require<br>
    <%= f.collection_select :type_id, Type.all, :id, :name, :prompt => "Select absence type" %>
    <br><br>
    <%= f.text_field :description %>
    <br><br>

    <%= f.submit "Submit Request", :class => "submit" %>
<% end %>
</form>

new.html.erb

<% provide(:title, 'apply for absence') %>

  <p>You have <b><%= @user.absentdays %></b> days of holiday time left.</p>
  <%= form_for @holiday do |f| %>
      <% if @holiday.errors.any? %>
          <div class="error_messages">
            <h2>Form is invalid</h2>
            <ul>
              <% for message in @holiday.errors.full_messages %>
                  <li><%= message %></li>
              <% end %>
            </ul>

      <% end %>
      Select the dates required for absence<br>
      start: <%= datepicker_input "holiday","start_at", :minDate => 0, :dateFormat => "yy-mm-dd" %><br>
      end: <%= datepicker_input "holiday","end_at", :minDate => 0, :dateFormat => "yy-mm-dd" %>
      <br><br>

      Please select the type of absence you require<br>
      <%= f.collection_select :type_id, Type.all, :id, :name, :prompt => "Select absence type" %>
      <br><br>
      Please provide a short description of the nature of your absence (if applicable)<br>
      <%= f.text_field :description %>
      <br><br>

      <%= f.submit "submit" %>

  <% end %>

</div>
  • 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-18T14:54:08+00:00Added an answer on June 18, 2026 at 2:54 pm

    The reason is, you are having a form in your holidays/show.html.erb but not in your holidays/new.html.erb.

    According to rails convention, if form is submitted in new.html.erb, then by default the POST method is called of that particular controller.

    But since your file is show.html.erb, you have to explicitly define your POST method in the form_for.

    form_for @holiday , :url => { :action => :create }, :html => { :method => "post"} do |f|
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails controller action to test. In that action, a method User.can?
Let's say I have a Rails 3 app that displays videos. The user can
I have a rails app using backbone. In the console, I can create a
I have a Rails controller named PagesController that is nested as follows in app/controllers/sevenpages/public/pages_controller.rb
I have a rails app whereby you can edit your account information. When I
I have a controller in a Rails 3 app that, after creating a new
I have a Rails App that lets Users register. Users can have several music
I have a rails app that has some simple functionality, allowing the user to
I have a medium-complex Rails app. The main controller (the one that does what
In my rails app, I have a loop in my controller that does this:

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.