I want to create a random selection generator, which should be called using a button<%= button_to("Randomize someting to do!", {:action => "random_task"}) %>
this calls method random task
def random_task
x = rand(Task.first.id..Task.last.id)
@task = Task.find(x)
rescue ActiveRecord::RecordNotFound => e
random_task
respond_to do |format|
format.html { render @task}
format.json { head :no_content }
end
end
This is supposed to call back my view/random_task.html.erb
<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>/tasks/
<div class="field">
<%= f.label :points %><br />
<%= f.number_field :points,:disabled=>true %>
</div>
<div class="rank_buttons">
<%= link_to 'Vote up', :action => 'rate_up', :id => task.id %>
<%= link_to 'Vote down', :action => 'rate_down', :id => task.id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Edit Q: How do I call the right way the rendering form if it is written ok?
If I understand correcty,
random_taskis not callingrandom_task.html.erb, right?random_taskshould be part of a controller. Andrand_task.html.erbshould be inside a folder with the same name as the controller in the views folder.If
random_taskis inrandoms_controller.rbfor example, addrandom_task.html.erbto the following path:views/randoms/then random_task should render the form you described.
I hope it helps