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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:40:14+00:00 2026-05-31T01:40:14+00:00

I’m working on assignment 2 problem 3 for saas class. I’m totally a rails

  • 0

I’m working on assignment 2 problem 3 for saas class. I’m totally a rails beginner, and having trouble with the problem.

The assignment asks you to make column name “movie title” a link, which sort the movies by name

What I’m doing is make “movie title” a link:

%th#title_header= link_to 'Movie Title', :controller => 'movies', :action => 'sort_by_title'

Add a custom action to movies_controller:

def sort_by_title
  @movies = Movie.find(:all, :order => "title")
  render movies_path
end

Then rails give me error:

No route matches {:controller=>"movies", :action=>"sort_by_title"}

Then I say ok and add it to the route file:

match '/movies?sort_by_title', :to => 'movies#sort_by_title'

Now the index page renders fine but nothing happens when click the movie_title link.

Am I on the right path or totally wrong?

The rake routes prints:

movies GET    /movies(.:format)               {:action=>"index", :controller=>"movies"}
       POST   /movies(.:format)               {:action=>"create", :controller=>"movies"}
new_movie GET    /movies/new(.:format)           {:action=>"new", :controller=>"movies"}
edit_movie GET    /movies/:id/edit(.:format)      {:action=>"edit", :controller=>"movies"}
movie GET    /movies/:id(.:format)           {:action=>"show", :controller=>"movies"}
       PUT    /movies/:id(.:format)           {:action=>"update", :controller=>"movies"}
       DELETE /movies/:id(.:format)           {:action=>"destroy", :controller=>"movies"}
              /movies?sort_by_title(.:format) {:controller=>"movies", :action=>"sort_by_title"}

Thank you

  • 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-31T01:40:15+00:00Added an answer on May 31, 2026 at 1:40 am

    Why create a route for this when it’s really just a GET parameter? It’s not a new action either, it’s still displaying all movies, just in a different manner.

    Modify your index action to do something like this:

    def index
      @movies = Movie.scoped
      @movies = @movies.order('title') if params['sort'] == 'title'
    end
    

    and then update your link:

    link_to 'Movie Title', movies_path(:sort => 'title')
    

    Resist the temptation to do just Movie.order(params['sort']) if params['sort'], as that opens up a potential SQL injection and, if not, just allows an attacker to discover all the columns in your table. It also has the potential to fail if the user just inputs a bad sort value in the URL.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.