Giter Site home page Giter Site logo

use of redirect_to about curriculum HOT 8 CLOSED

turingschool avatar turingschool commented on July 18, 2024
use of redirect_to

from curriculum.

Comments (8)

steveklabnik avatar steveklabnik commented on July 18, 2024

Which tutorial was this in?

from curriculum.

khristian avatar khristian commented on July 18, 2024

Steve,

It was in JSBlogger: http://tutorials.jumpstartlab.com/projects/jsblogger.html

from curriculum.

steveklabnik avatar steveklabnik commented on July 18, 2024

Hm. article_path should be correct there. Can you show me what your routes.rb file has in it?

from curriculum.

khristian avatar khristian commented on July 18, 2024

Thanks for looking into this Steve.

My routes.rb file is:

Jsblogger::Application.routes.draw do
#create a resource names articles
resources :comments
resources :articles

The priority is based upon order of creation:

first created -> highest priority.

Sample of regular route:

match 'products/:id' => 'catalog#view'

Keep in mind you can assign values other than :controller and :action

Sample of named route:

match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase

This route can be invoked with purchase_url(:id => product.id)

Sample resource route (maps HTTP verbs to controller actions automatically):

resources :products

Sample resource route with options:

resources :products do

member do

get 'short'

post 'toggle'

end

collection do

get 'sold'

end

end

Sample resource route with sub-resources:

resources :products do

resources :comments, :sales

resource :seller

end

Sample resource route with more complex sub-resources

resources :products do

resources :comments

resources :sales do

get 'recent', :on => :collection

end

end

Sample resource route within a namespace:

namespace :admin do

# Directs /admin/products/* to Admin::ProductsController

# (app/controllers/admin/products_controller.rb)

resources :products

end

You can have the root of your site routed with "root"

just remember to delete public/index.html.

root :to => 'welcome#index'

See how all your routes lay out with "rake routes"

This is a legacy wild controller route that's not recommended for RESTful applications.

Note: This route will make all actions in every controller accessible via GET requests.

match ':controller(/:action(/:id(.:format)))'

end

Here are my routes:

Ping:jsblogger admin$ rake routes
comments GET /comments(.:format) {:action=>"index", :controller=>"comments"}
POST /comments(.:format) {:action=>"create", :controller=>"comments"}
new_comment GET /comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_comment GET /comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
comment GET /comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
articles GET /articles(.:format) {:action=>"index", :controller=>"articles"}
POST /articles(.:format) {:action=>"create", :controller=>"articles"}
new_article GET /articles/new(.:format) {:action=>"new", :controller=>"articles"}
edit_article GET /articles/:id/edit(.:format) {:action=>"edit", :controller=>"articles"}
article GET /articles/:id(.:format) {:action=>"show", :controller=>"articles"}
PUT /articles/:id(.:format) {:action=>"update", :controller=>"articles"}
DELETE /articles/:id(.:format) {:action=>"destroy", :controller=>"articles"}

from curriculum.

steveklabnik avatar steveklabnik commented on July 18, 2024

of course!

article GET /articles/:id(.:format) {:action=>"show", :controller=>"articles"}

Yeah. Should be article_path(article). How strange. Could you maybe upload the app to a repo so I could play around with it?

from curriculum.

khristian avatar khristian commented on July 18, 2024

Steve,

Try this: https://github.com/khristian/test

This is the first time I've created a repo so let me know if this isn't what you need.

Thanks again.

from curriculum.

steveklabnik avatar steveklabnik commented on July 18, 2024

That's great! Looking at it now.

from curriculum.

steveklabnik avatar steveklabnik commented on July 18, 2024

Turns out the problem is unrelated, and this is just a really, really poor error message:

https://github.com/khristian/test/blob/master/app/controllers/comments_controller.rb#L4

This should be Comment.new(params[:comment]), because params[:article] is nil. When it's nil, and you try to give nil to comment_path, it throws that error. Which is dumb.

Let me know if I can help clear up any confusion about this.

from curriculum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.