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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:42:03+00:00 2026-05-24T10:42:03+00:00

I currently have a very simple model Coupon. I suddenly am interested to add

  • 0

I currently have a very simple model “Coupon”. I suddenly am interested to add two more fields, “redeem_code” and “redeemed” to the model for obvious reasons.

I would like to make a view for a merchant to redeem a coupon based on a code.

The simplest approach that I can think of to just do this would be something like this:

  def redeem
    #renders the page
  end

  def redeem_post
    redeem_code = params[:redeem_code]
    deal = Deal.find_by_redeem_code(redeem_code)

    if deal.nil? 
      # BUG: Somehow here you will be logged out 
      redirect_to deals_path
    else 
      if deal.update_attribute(:redeemed, true)
        redirect_to deals_path
      end
    end
  end

As far as I am concerned, rails doesn’t really support non restful interfaces. I tried digging up form helpers last night but I was not able to find anything so I just put togehter something real fast:

<form action="<%= deals_redeem_post_path %>" method="post">

  <table>
    <tr>
      <th> Code: </th>
      <td> <input type="text" name="redeem_code" /> </td>
    </tr>
    <tr>
      <th></th>
      <td> <input type="submit" text="Submit" /> </td>
    </tr>
  </table>

</form>

I am using devise. The bug that I am experiencing right now is when my user submits this form, he/she will be automatically logged out.

Any ideas how I can fix this or implement this more elegantly?

  • 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-24T10:42:04+00:00Added an answer on May 24, 2026 at 10:42 am

    My guess is that you are missing the authenticity token (which prevents Cross Site Request Forgery (CSRF)) which is automatically generated. You want to use the form for helper for that generates this automatically.

    <%= form_for(:coupon, :url => deals_redeem_post_path) do |f| %>
    

    http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for

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

Sidebar

Related Questions

I am currently using Django Users model. Very simple. However, I'd like to add
I have a public class called Profile . Very simple model class currently with
I currently have a very simple MySQL database (articlesDB) with 1 table (articles) and
Very simple + silly question: Does clojure provide multi maps? I currently have something
I have a (currently very simple) website that is utilising Facebook's Website with Facebook
I have a very simple interface which needs to communicate between processes. It's currently
I have a very simple model that includes the auto-filled field much like 'created'.
I have a very simple JavaScript/jquery code which won't just work correctly. The problem
I am currently using tomcat 6 as my Web Server. I have a very
im currently learning python (in the very begining), so I still have some doubts

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.