我想更改show
路径以使其更适合搜索引擎优化。当我拿出form_for
的edit
页面上导轨路由:更改资源的“显示”路径
No route matches {:controller=>"posts", :action=>"show", :format=>nil, :id=>#<Post id: 1, title: "2 Pick Parlay", content: "<h1>Here you go</h1>\r\nStarting off the 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">}
:下面的代码试图去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
错误时抛出一个错误。 。页面呈现。所以这个问题必须在此代码是edit
页上edit.haml.html
违规代码:
= form_for(@post) do |f|
%h3
Title for write up
= f.text_field(:title, :class => "field span8")
%br
%br
%h3
Your 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. Then you may need to shorten the tweet to 140 characters. Most people remove the city name from the 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 to tweet my current full card", "https://twitter.com/intent/tweet?text=#{@picks_tweet_string}", confirm: "Click OK below. Then you may need to shorten the tweet to 140 characters. Most people remove the city name from the picks."
- else
= link_to "I want to tweet my current full card", "https://twitter.com/intent/tweet?text=#{@picks_tweet_string}"
%br
%br
= f.submit "SUMBIT THIS WRITE-UP", class: 'btn-xlarge btn-block btn-primary'
%br
%br
= f.submit "No additional write-up", class: 'btn-xlarge btn-block btn-primary'
任何想法有什么错呢?
从form_for更改form_tag已工作。 form_tag(“/ posts/#{@post.id}”,方法:: put)do – slindsey3000
最后..我去了这个form_for(@post,url:{action:“update”})do | f | ......当然,我更新了我的代码块以包含f表单助手。但form_tag也可以像我在上面的评论中提到的那样工作。 – slindsey3000