diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb new file mode 100644 index 0000000..74703cd --- /dev/null +++ b/app/controllers/books_controller.rb @@ -0,0 +1,23 @@ +class BooksController < ApplicationController + def new + @books = Book.new + end + + def create + @books = Book.new(book_params) + if @books.save + flash[:info] = I18n.t('es.flash.book.created') + redirect_to @books + else + render 'new' + end + end + + def show + @books = Book.find(params[:id]) + end + + def book_params + params.require(:book).permit(:title) + end +end \ No newline at end of file diff --git a/app/helpers/book_helper.rb b/app/helpers/book_helper.rb new file mode 100644 index 0000000..4872edd --- /dev/null +++ b/app/helpers/book_helper.rb @@ -0,0 +1,2 @@ +module BookHelper +end \ No newline at end of file diff --git a/app/views/books/new.html.erb b/app/views/books/new.html.erb new file mode 100644 index 0000000..a556bc4 --- /dev/null +++ b/app/views/books/new.html.erb @@ -0,0 +1,9 @@ +
+ <%= form_for(@books) do |f| %> + <%= render 'shared/error_messages', object: f.object %> + <%= f.label :title %> + <%= f.text_field :title, placeholder: true %> + + <%= f.submit %> + <% end %> +
diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb new file mode 100644 index 0000000..1196a1f --- /dev/null +++ b/app/views/books/show.html.erb @@ -0,0 +1,4 @@ +<% flash.each do |message_type, message| %> + <%= content_tag(:div, message, class: "alert alert-#{message_type}") %> +<% end %> +

<%= @books.title %>

diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb index a3617eb..f9c5b88 100644 --- a/app/views/static_pages/home.html.erb +++ b/app/views/static_pages/home.html.erb @@ -1,5 +1,6 @@

Recetame App

<%= link_to t('button.recipe.create'), new_recipe_path %> +<%= link_to t('button.book.create'), new_book_path %>

Aquí están las últimas 10 recetas