Ruby on rails 铁轨:;未知行动“;明确指定操作时的消息
我花了很长时间才弄明白为什么在编辑时会收到“未知操作”错误消息:Ruby on rails 铁轨:;未知行动“;明确指定操作时的消息,ruby-on-rails,action,Ruby On Rails,Action,我花了很长时间才弄明白为什么在编辑时会收到“未知操作”错误消息: Unknown action No action responded to 11. Actions: bin, create, destroy, edit, index, new, observe_new, show, tag, update, and vote 您可以看到Rails在上面的列表-update中提到了每个操作。在我的表格中,我确实指定了action=“update” 我想知道一些朋友是否能帮我处理丢失的链接 代
Unknown action
No action responded to 11. Actions: bin, create, destroy, edit, index, new, observe_new, show, tag, update, and vote
您可以看到Rails在上面的列表-update中提到了每个操作。在我的表格中,我确实指定了action=“update”
我想知道一些朋友是否能帮我处理丢失的链接
代码如下:
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
edit.rhtml
编辑提示
'更新',:id=>@tip do%>
'表格'%>
_form.rhtml
标题
类别
正确)%%>
摘要:
名称:
链接:
内容
5%>
标签(空格分隔)
40%>
类TipsController<应用程序控制器
在筛选器之前:验证,:除=>%w(索引显示)
#获取/提示
#GET/tips.xml
def索引
@tips=Tip.all
回应待办事项|格式|
format.html#index.html.erb
format.xml{render:xml=>@tips}
结束
结束
#获取/提示/1
#GET/tips/1.xml
def秀
@tip=tip.find_by_permalink(参数[:permalink])
回应待办事项|格式|
format.html#show.html.erb
format.xml{render:xml=>@tip}
结束
结束
#获取/提示/新建
#GET/tips/new.xml
def新
@tip=会话[:tip_draft]| | current_user.tips.build
结束
def创建
#tip=当前用户.tips.build(参数[:tip])
#tipMail=params[:电子邮件]
#如果是tipMail
#TipMailer.deliver\u email\u friend(参数[:email],参数[:name],提示)
#flash[:notice]=“已通知您的朋友此提示”
#结束
@tip=当前用户.tips.build(参数[:tip])
@提示:类别“索引”
其他的
呈现:操作=>“新建”
结束
结束
定义编辑
@tip=tip.find(参数[:id])
结束
def更新
@tip=tip.find(参数[:id])
回应待办事项|格式|
如果@tip.update_属性(参数[:tip])
flash[:notice]=“提示已成功更新。”
format.html{redirect_to(@tip)}
format.xml{head:ok}
其他的
format.html{render:action=>“edit”}
format.xml{render:xml=>@tip.errors,:status=>:unprocessable_entity}
结束
结束
结束
def销毁
@tip=tip.find(参数[:id])
@提示:销毁
回应待办事项|格式|
format.html{重定向到(提示url)}
format.xml{head:ok}
结束
结束
def observe_new
会话[:tip\u draft]=当前用户.tips.build(参数[:tip])
render:nothing=>true
结束
结束
快速的答案是表单标签不支持:action作为选项,您希望将字符串作为路径传入。一个稍微长一点的答案是,您不应该对模型编辑表单使用form_标记,而应该对模型编辑表单使用form_标记
你用的是什么栏杆。rhtml已经很老了,rails生成器应该会给你.html.erb文件。如果它是最近的东西,你应该能够使用
<% form_for @tip do |f| %>
<%= f.label :title, 'Title' %><br />
<%= f.text_field %>
... etc
<% end %>
... 等