开发者

_form partial undefined method `staticpages_path' error

开发者 https://www.devze.com 2023-02-05 05:49 出处:网络
Something wrong in my partial: <% form_for(@static) do |f| %> <%= f.error_messages %> <div class=\"field\">

Something wrong in my partial:

<% form_for(@static) do |f| %>
  <%= f.error_messages %>

  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :content %><br />
    <%= f.text_area :content %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

The edit method:

def edit
    @static=Staticpage.find(params[:id])
  end

And 开发者_JAVA百科I use this solution in the routes.rb

resources :static

Whats wrong?


The reason is that your model is called Staticpage, but in your routes you only call it static so that does not match. You can solve this in a number of ways. For example:

#routes.rb
resources :staticpages

If you don't want to do that then you could also manually specify the path in your call to form_for like this:

<% form_for(@static, :url => static_path) do |f| %>

And also, you could rename your model to Static, but I think that is more complicated solution since it will probably affect a lot of other thing as well.


rake routes

in terminal see what's your path,

it could be the routes.rb, maybe

resources :staticpages

? just a guess

0

精彩评论

暂无评论...
验证码 换一张
取 消