2010-06-11 4 views
1

J'ai eu du mal à comprendre pourquoi je reçois un message d'erreur « action inconnue » quand j'étais faire de l'édition:rails: « action inconnue » lorsque l'action est clairement spécifié

Unknown action 
No action responded to 11. Actions: bin, create, destroy, edit, index, new, observe_new, show, tag, update, and vote 

vous pouvez voir que Rails a mentionné chaque action dans la liste ci-dessus - mise à jour. Et dans mon formulaire, j'ai spécifié action = "update".

Je me demande si quelques amis bien vouloir me aider avec les liens manquants ...

Voici le code:

edit.rhtml 

<h1>Editing tip</h1> 

<% form_tag :action => 'update', :id => @tip do %> 
    <%= render :partial => 'form' %> 

    <p> 
    <%= submit_tag_or_cancel 'Save Changes' %> 
    </p> 
<% end %> 

_form.rhtml 

<%= error_messages_for :tip %> 

<p><label>Title<br/> 
<%= text_field :tip, :title %></label></p> 

<p><label>Categories<br/> 
<%= select_tag('categories[]', options_for_select(Category.find(:all).collect {|c| [c.name, c.id] }, @tip.category_ids), :multiple => true) %></label></p> 

<p><label>Abstract:<br/> 
<%= text_field_with_auto_complete :tip, :abstract %></label></p> 

<p><label>Name: <br/> 
<%= text_field :tip, :name %></label></p> 

<p><label>Link: <br/> 
<%= text_field :tip, :link %></label></p> 

<p><label>Content<br/> 
<%= text_area :tip, :content, :rows => 5 %></label></p> 

<p><label>Tags <span>(space separated)</span><br/> 
<%= text_field_tag 'tags', @tip.tag_list, :size => 40 %></label></p> 

class TipsController < ApplicationController 
before_filter :authenticate, :except => %w(index show) 

    # GET /tips 
    # GET /tips.xml 
    def index 
    @tips = Tip.all 
    respond_to do |format| 
     format.html # index.html.erb 
     format.xml { render :xml => @tips } 
    end 
    end 

    # GET /tips/1 
    # GET /tips/1.xml 
    def show 
    @tip = Tip.find_by_permalink(params[:permalink]) 
    respond_to do |format| 
     format.html # show.html.erb 
     format.xml { render :xml => @tip } 
    end 
    end 

    # GET /tips/new 
    # GET /tips/new.xml 
def new 
    @tip = session[:tip_draft] || current_user.tips.build 
    end 

def create 
    #tip = current_user.tips.build(params[:tip]) 
    #tipMail=params[:email] 
    #if tipMail 
    # TipMailer.deliver_email_friend(params[:email], params[:name], tip) 
    # flash[:notice] = 'Your friend has been notified about this tip' 
    #end 

    @tip = current_user.tips.build(params[:tip]) 
    @tip.categories << Category.find(params[:categories]) unless params[:categories].blank? 
    @tip.tag_with(params[:tags]) if params[:tags] 

    if @tip.save 
     flash[:notice] = 'Tip was successfully created.' 
     session[:tip_draft] = nil 
     redirect_to :action => 'index' 
    else 
     render :action => 'new' 
    end 
    end 


    def edit 
    @tip = Tip.find(params[:id]) 
    end 

    def update 
    @tip = Tip.find(params[:id]) 
    respond_to do |format| 
     if @tip.update_attributes(params[:tip]) 
     flash[:notice] = 'Tip was successfully updated.' 
     format.html { redirect_to(@tip) } 
     format.xml { head :ok } 
     else 
     format.html { render :action => "edit" } 
     format.xml { render :xml => @tip.errors, :status => :unprocessable_entity } 
     end 
    end 
    end 


    def destroy 
    @tip = Tip.find(params[:id]) 
    @tip.destroy 

    respond_to do |format| 
     format.html { redirect_to(tips_url) } 
     format.xml { head :ok } 
    end 
    end 



def observe_new 
    session[:tip_draft] = current_user.tips.build(params[:tip]) 
    render :nothing => true 
    end 


end 

Répondre

0

la réponse rapide est que form_tag ne supporte pas: l'action en tant option, vous voulez passer une chaîne comme un chemin d'accès. Une réponse légèrement plus longue est que vous ne devriez pas utiliser form_tag de toute façon pour un formulaire d'édition de modèle, vous devriez utiliser form_for.

Quels rails utilisez-vous? .rhtml est assez vieux, les générateurs de rails devraient vous donner des fichiers .html.erb. si c'est quelque chose de très récent, vous devriez pouvoir utiliser

<% form_for @tip do |f| %> 
    <%= f.label :title, 'Title' %><br /> 
    <%= f.text_field %> 
    ... etc 
<% end %> 
Questions connexes