Render a show view html with some restrictions

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?

Answers


If I understand correcty, random_task is not calling random_task.html.erb, right?

random_task should be part of a controller. And rand_task.html.erb should be inside a folder with the same name as the controller in the views folder.

If random_task is in randoms_controller.rb for example, add random_task.html.erb to the following path: views/randoms/

then random_task should render the form you described.

I hope it helps


Need Your Help

Send/Receive Email from within Web Application?

java email java-ee web-applications smtp

I have an Order Management (Web) Application (in Java/Java EE).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.