Rails routing: Changing the 'show' path for a resource -


i change show path make more seo friendly. code below throws error when trying go edit

routes.rb

resources :posts, :only => [:index, :new, :create, :update, :edit]  match "posts/:id/:league_name/:post_description", to: 'posts#show', :as => :post, via: :get 

error:

no route matches {:controller=>"posts", :action=>"show", :format=>nil, :id=>#<post id: 1, title: "2 pick parlay", content: "<h1>here go</h1>\r\nstarting off season right...", link: nil, created_at: "2016-07-31 21:45:40", updated_at: "2016-07-31 22:01:58", user_id: 2, league_id: 1, initial_status: nil, home_team: "", favorite: "", points: nil, visiting_team: "", event_datetime: "2016-09-09 00:30:00", spread_home: nil, spread_away: nil, total_points: nil, user_spread: nil, user_team_pick: nil, user_total_pick: nil, user_total_points: nil, user_line_source: nil, post_type: nil, event_id: 137, subscriber_only: false, release_at_gametime: false, is_parlay: true, flagged: false, weight: 1, post_description: "pick">} 

when take out form_for on edit page .. page renders. problem must in code on edit page

offending code in edit.haml.html:

    = form_for(@post) |f|      %h3       title write     = f.text_field(:title, :class => "field span8")     %br     %br     %h3       analysis     = f.text_area(:content, :class => "field span8", :rows => "5")     <br/>     = f.hidden_field(:league_id)       = f.hidden_field(:event_id)      = f.hidden_field(:home_team)      = f.hidden_field(:visiting_team)     = f.hidden_field(:favorite)      = f.hidden_field(:points)      = f.hidden_field(:event_datetime)       %br     %br       %h4       - if @picks_tweet_string && @just_this_post_tweet_string         - if @just_this_post_tweet_string.size > 130           = link_to "tweet these picks out now", "https://twitter.com/intent/tweet?text=#{@just_this_post_tweet_string}", confirm: "click ok below. may need shorten tweet 140 characters. people remove city name picks."         - else             = link_to "tweet these picks out now", "https://twitter.com/intent/tweet?text=#{@just_this_post_tweet_string}"         %br           - if @picks_tweet_string.size > 130           = link_to "i want tweet current full card", "https://twitter.com/intent/tweet?text=#{@picks_tweet_string}", confirm: "click ok below. may need shorten tweet 140 characters. people remove city name picks."         - else             = link_to "i want tweet current full card", "https://twitter.com/intent/tweet?text=#{@picks_tweet_string}"           %br         %br       = f.submit "sumbit write-up", class: 'btn-xlarge btn-block btn-primary'      %br     %br     = f.submit "no additional write-up", class: 'btn-xlarge btn-block btn-primary' 

any ideas wrong that?

it's bit complicated, you've changed show route, you've indirectly changed edit route. edit route based on show route. example:

show => "posts/:id" edit => "posts/:id/edit" 

now you'll have make edit route is:

"posts/:id/:league_name/:post_description" 

in order in edit form:

= form_for([@post, @league, post_description: @post.post_description) |f| 

this assuming @league object's to_param method returns league_name, otherwise you'd have write:

= form_for([@post, league_name: @league.league_name, post_description: @post.post_description) |f| 

i'm sure can see level of complexity may not desired how rails works. hence adage: "convention on configuration"


Comments