我试图通过在页面上按下一个按钮来实现以下目标,用户可以从数据库中获取一个随机项目,该项目将被显示,但将具有可编辑的属性。我遇到的问题是以下我不知道如何传递随机 id(在数据库中有效),以在我的部分中呈现,但仍然能够更新特定属性。
标题中的问题:
SyntaxError in Tasks#main
Showing /home/bogdan/ex/bored/app/views/tasks/main.html.erb where line #1 raised:
/home/bogdan/ex/bored/app/views/tasks/main.html.erb:1: syntax error, unexpected ',', expecting ')'
...uffer.append= form_for (:task, :url => {:action =>'rand_tas...
... ^
/home/bogdan/ex/bored/app/views/tasks/main.html.erb:1: syntax error, unexpected ')', expecting keyword_end
...url => {:action =>'rand_task'}) do |f|@output_buffer.safe_co...
... ^
../app/views/tasks/main.html.erb:8: syntax error, unexpected keyword_ensure, expecting $end
Extracted source (around line #1):
1: <%= form_for (:task, :url => {:action =>'rand_task'}) do |f|%>
2: <%= render(:partial => "rand_show", :locals => {:f => f}) %></p>
3: <%end%>
4:
Trace of template inclusion: app/views/tasks/main.html.erb
我试图将 rand_task 输出对象传递给 _rand_show.html.erb 并且 afterwartds 只为我感兴趣的 attr 调用一个新的可编辑表单id
形式:
<%= form_for(@task = Task.new) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, :disabled=>true %>
</div>
<div class="field">
<%= f.label :category %><br />
<%= f.text_field :category, :disabled=>true %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
随机方法:
def rand_task
if params[:id] == 'random'
@task = Task.order('RANDOM()').first
else
@task = Task.order('RANDOM()').first // if not i get a nill related error.
end
end
请帮助我为什么会收到上述错误?我正在考虑的概念是错误的吗?