views:

23

answers:

2

I have one model: new and its controller: news

The news controller methods:

    def edit
    @new = New.find(params[:id].to_i)
  end

  def update
    @new = New.find(params[:id].to_i)
    @new.update_attributes(params[:new])
    flash[:notice] = "Sikeresen frissítve"
    redirect_to news_path
  rescue ActiveRecord::RecordInvalid
    flash[:error] = "Valami hiba lépett fel"
    redirect_to edit_news_path(@new)
  end

And here is the edit.html.erb

<%= error_messages_for :news %>

<% form_for :new, :url=>news_path(@new), :html=>{:method=>:put}  do |m|%>

  <p>  <%= m.label(:title,"title: ") %>

  <%= m.text_field(:title) %></p>

  <p>

    <%= m.label(:text, "text: ") %>

    <%= m.text_area(:text) %>

  </p>

    <%= submit_tag "Save" %>

<% end %>

It's works fine, no error, the field showed up in the textboxes, but if I click the submit button I gave unknown action error

A: 

Try this:

form_for :new, :url=>{ :action => "update" }, :html=>{:method=>:put}  do |m|
bjg
+3  A: 

I think it should be

:url=>new_path(@new)

not

:url=>news_path(@new)

though i'm confused just thinking about it due to you calling your model "new".

I STRONGLY recommend you change your model name (and controller and views) to avoid confusion. "New" is used in rails in the context of the 'new' action. If you don't change it you will have things like "new_new_path" and "update_new_path" which is going to make you cry at some point.

Also, it doesn't really make sense to talk about 'a new'. The singular of 'news' isn't 'new'. It's very confusing all round, sort it out now before you build any more stuff around it.

I'd recommend "Article" or something similar as a model name.

Max Williams
If the OP wants to stick with news as his controller name he could change the inflector to make "news" uncountable
Steve Weet