As a newbie in web development, I am embarking on a project using Ruby on Rails (3.2.9) and have some uncertainties about the capabilities of RoR without JavaScript. For instance, when using a Rails Scaffold, creating new database records by accessing the Controller's new method (subsequently calling the create method to save the record) is quite straightforward.
Now, I'm interested in creating new records without having a separate view for it. Picture this: "User clicks a button -> record is saved". To illustrate, let's say I have a view displaying articles generated from a Rails scaffold command and I've included a link to a "buy" method revealing the article name and available quantity with an input field for selecting the desired amount to purchase.
<p>
<b>Name:</b>
<%= @article.name %>
</p>
<p>
<b>Available:</b>
<%= @article.stocks %>
</p>
<%= form_for(@article) do |f| %>
<div class="field">
<b>How many?</b>
<br />
<%= f.number_field :amount %>
</div>
<% end %>
My objective now is to add a link or a button triggering an event that converts the selected article and quantity into an order item, essentially creating a record in the order_item table.
<td><%=link_to "Yes", :controller => "oderItem", :method => "create" %></td><br>
I'm uncertain about the approach to take. I considered solely utilizing the create method or any relevant method within the Controller like:
def match
@apo = OrderItem.new(:amount :2, ...)
@apo.save
end
However, it appears to redirect me to the new method of the controller or something similar.
Considering my explanations, can someone advise if I'm making a mistake with Rails or if I should resort to using JavaScript?
In conclusion, I would appreciate simple sample code (whether for Rails or JS) and links to straightforward code examples demonstrating projects like this on Rails. Keeping it basic would be ideal as I aim to make this functional without delving into advanced techniques like Ajax.