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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:34:09+00:00 2026-05-13T22:34:09+00:00

Im not sure if I’m doing this right. I have an action that I

  • 0

Im not sure if I’m doing this right. I have an action that I would like to either copy, create, and save a new object if a user is logged in, or redirect if they are not logged in. Im not using a form here because I am using a stylized button with an image that looks like this:

<a href="/lists/add/<%= @list.id %>" class="button">
  <span class="add_list">Learn these words</span>
</a>

and the action looks like this:

  def add    
    if is_logged_in?  
      list = logged_in_user.copy_list(params[:id])
      if list.save
        flash[:notice] = "This list is now in your stash."
        redirect_to stash_zoom_nav_quiz_path(list, "zoomout", "new", "quizoff")
      else
        flash[:notice] = "There was a problem adding this list."
        redirect_to :back
      end
    else
      redirect_to :controller => "users", :action => "signup_and_login", :list_id => params[:id]    
    end
  end

map.resources :lists, :collection => {:share => :get, :share_callback => :get, :add => :put}

I have added this action as a :put in my routes and I’m not sure if this is right or if the other stuff is the right way to even do it for that matter. 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-05-13T22:34:10+00:00Added an answer on May 13, 2026 at 10:34 pm

    The specific answer to your question is

    map.resources :lists, :collection => { :share => :get, :share_callback => :get }, :member => { :add => :put }
    

    add action works on a member, not on a collection.

    But there are other problems in your code. First, you should always use Rails helpers to generate the URLs. In fact, the path /lists/add/<%= @list.id %> is wrong. It should be /lists/<%= @list.id %>/add

    Change

    <a href="/lists/add/<%= @list.id %>" class="button">
      <span class="add_list">Learn these words</span>
    </a>
    

    to

    <% link_to add_list_path(@list), :class => "button" do %>
      <span class="add_list">Learn these words</span>
    <% end %>
    

    The controller can be simplified. Move the is_logged_in? check in a before filter.

    class MyController < ActionController::Base
    
      before_filter :require_logged_user, :only => %w( add )
    
      def add    
        list = logged_in_user.copy_list(params[:id])
        if list.save
          flash[:notice] = "This list is now in your stash."
          redirect_to stash_zoom_nav_quiz_path(list, "zoomout", "new", "quizoff")
        else
          flash[:notice] = "There was a problem adding this list."
          redirect_to :back
        end
      end
    
      protected
    
      def require_logged_user
        if !is_logged_in?
          redirect_to :controller => "users", :action => "signup_and_login", :list_id => params[:id]
        end
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure if anyone has experience this issue. I have a TextBox that I
Not sure if I can word this right but here we go. I have
Not sure what to call this, Option would fit just as well as Either,
Not sure if this is possible, but I have seen a few people doing
Not sure how to ask this, but i'll give it a try: I have
Not sure if that the right title for the question, but what I'm trying
Not sure what parallel programing means... but I have two thoughts of that Process
Not sure if this is the right place to ask, but I found this
Not sure if this is possible but I have a slideshow on my site
Not sure if this is the right place for MDX question but it seemed

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.