i need post confirmation page
i have that form:
<%= form_for(#domainpost, :url => {:action => "confirm"}) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field" id="content">
<b><p>Adres domeny: <span class="label label-important">Pole wymagane</span>
</p></b><%= f.text_area :content, placeholder: "bez www." %>
</div>
<div class="field" id="additiona">
<p>Dodatkowe końcówki: </p><%= f.text_area :additiona, placeholder: "np. .de, .fr" %>
</div>
<div class="field" id="registerdate">
<p>Data rejestracji domeny: </p><%= f.text_area :registerdate, placeholder: "DD-MM-RRRR" %>
</div>
<div class="field" id="expiredate">
<p>Data ważności: </p><%= f.text_area :expiredate, placeholder: "DD-MM-RRRR" %>
</div>
<div class="field" id="registerin">
<p>Zarejestrowane w: </p><%= f.text_area :registerin, placeholder: "miejsce rejestracji" %>
</div>
<div class="field" id="price">
<b><p>Cena: (jeżeli zostawisz to pole puste, w opisie domeny wyświetli się "do negocjacji")</p></b><%= f.text_area :price, placeholder: "w PLN" %>
</div>
<%= f.submit "Dodaj", class: "btn btn-large btn-primary" %>
<% end %>
in controler i put
def preview
#domainpost = Domainpost.new(params[:domainpost])
end
and i in routes.rb i put
resources :domainpost do
:confirm, :on => :collection
end
but it dont work
any idea what i can do for post confirmation page?
Related
ruby 2.1.5
rails 4.2.1
I am trying to figure out how to access a virtual attribute from params.
In my books_controller.rb, I have:
wrap_parameters :books_list
def product_params
params.require(:product).permit(:author_name, :book_name, :books_list)
end
Obviously, the books_list is the virtual attribute. I will be saving it to the books_list table
In my new.html.erb,I have:
<% #title = "Books" %>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<%= form_for(#books, html: { class: 'form-horizontal' }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.form_group :author_name do |f| %>
<%= f.label :author_name, class: 'control-label col-md-2' %>
<div class='col-md-8'>
<%= f.text_field :author_name, class: 'form-control' %>
<%= f.error_messages %>
</div>
<% end %>
<div class="form-inputs">
<%= f.form_group :book_name do |f| %>
<%= f.label :book_name, class: 'control-label col-md-2' %>
<div class='col-md-8'>
<%= f.text_field :book_name, class: 'form-control' %>
<%= f.error_messages %>
</div>
<% end %>
<%= f.form_group :books_list do |f| %>
<%= f.label :books_list, class: 'control-label col-md-2' %>
<div class='col-md-8'>
<%= f.text_area :books_list, class: 'form-control' %>
<%= f.error_messages %>
</div>
<% end %>
</div>
<div class="form-actions col-md-offset-2 col-md-10">
<%= f.submit class: 'btn btn-primary' %>
<%= link_to "Cancel", test_sets_path, class: 'btn' %>
</div>
<% end %>
</div>
</div>
</div>
When I submit the form, here's what I get for params:
Parameters: {
"utf8"=>"✓",
"authenticity_token"=>"5mxkibQHkwRnzVU31A6pe9uezsmaWeYbCUgU+gUZPLmiAZPnN6si+smdEePU0lfGITh7gmmyChf/bOY+YQQcQg==",
"books"=>{"author_name"=>"Some Author", "book_name"=>"Dwan Of The Dead"},
"books_list"=>{"{:class=>\"form-control\"}"=>"book1\r\nbook2"},
"commit"=>"Create Book List"
}
I am having trouble accessing the books_list in params. Any ideas?
If books_list column is not exist in #book, it raises error.
There is no method f.form_group in rails, I think you use gem that defines form_group method.
Maybe "books_list"=>{"{:class=>\"form-control\"}"=>"book1\r\nbook2"} parameter is made by some bootstrap gem. you check check name attribute in html source.
I have a rails app where user can assign task to another user by creating task action. At the moment I have the f.collection_select, but as the number of users grows it won't be a good solution. I would like to change it into kinda search form. My problem is that I don't see how I can do this. I have other search forms, but those are for show/index action. How can I do this for the create action?
here is my current code:
<%= form_for ([#user, #task]) do |f| %>
<%= render 'layouts/error_messages', object: f.object %>
<div class="field form-group">
<%= f.label :executor_id %>
<%= f.collection_select(:executor_id, User.all, :id, :email, class: "form-control") %>
</div>
<div class="field form-group">
<%= f.label :content %>
<%= f.text_area :content, class: "form-control" %>
</div>
<div class="field form-group">
<%= f.label :deadline %>
<%= f.date_select :deadline, class: "form-control" %>
</div>
<div class="actions">
<%= f.submit "Create Task", class: 'btn btn-primary', "data-sid" => current_user.id, "data-rip" => :executor_id %>
</div>
<% end %>
I'm creating a simple form in rails and the submit button doesn't work. I think I'm missing something obvious here but the html seems to be fine (I'm far froma front end expert). Any advice or pointers?
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2>Apply</h2>
<hr class="star-primary">
</div>
</div>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="row control-group">
<% if #user.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(#user.errors.count, "error") %>.
</div>
<ul>
<% #user.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="col-xs-12 floating-label-form-group controls">
<%= form_for #user, url: users_path(#user), :html => {:method => :post} do |f| %>
<%= f.label :name %>
<%= f.text_field :name, class: "form-control", placeholder: 'Name' %>
<%= f.label :email%>
<%= f.text_field :email, class: "form-control", placeholder: "Email" %>
<%= f.label :address%>
<%= f.text_field :address, class: "form-control", placeholder: "Address" %>
<%= f.label :phone %>
<%= f.text_field :phone, class: "form-control", placeholder: "Phone Number" %>
<%= f.submit "Apply"%>
<%end%>
</div>
</div>
</div>
</div>
</div>
Also, when the submit button fails, nothing happens. No error messages, no console errors. Nothing.
Take method out from the html hash?
form_for #user, url: users_path(#user), :method => :post do |f|
Try this:
<%= form_for #user, :url => {:controller => "your-controller-name", :action => "your-action-name"} do |f| %>
Can you try this one:
<%= form_for #user, url: {action: "create"} do |f| %>
...
...
<%= f.submit "Apply" %>
<% end %>
But I strongly suggest you to use simple_form gem.
I'm trying to create an update form that would modify ( add or remove ) images related to a product. Each product has many images , each image belongs to a product.
When a user wants to modify a product , the idea is that all the images related to the product displayed and the user decides whether to add more or remove them. My problem is I do not know how to make the images appear. I can only make it show the link.
edit.html.erb
<%- model_class = Product -%>
<div class="page-header">
<h1><%=t '.title', :default => [:'helpers.titles.edit', 'Edit %{model}'], :model => model_class.model_name.human.titleize %></h1>
</div>
<%= render :partial => 'form' %>
_form.html.erb
<%= form_for #product, :html => { :class => "form-horizontal product" } do |f| %>
<% if #product.errors.any? %>
<div id="error_expl" class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title"><%= pluralize(#product.errors.count, "error") %> prohibited this product from being saved:</h3>
</div>
<div class="panel-body">
<ul>
<% #product.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
</div>
<% end %>
<div class="control-group">
<%= f.label :name, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :name, :class => 'form-control' %>
</div>
<%= error_span(#product[:name]) %>
</div>
<div class="control-group">
<%= f.label :price, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :price, :class => 'form-control' %>
</div>
<%= error_span(#product[:price]) %>
</div>
<div class="control-group">
<%= f.label :stock, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :stock, :class => 'form-control' %>
</div>
<%= error_span(#product[:stock]) %>
</div>
<div class="control-group">
<%= f.label :tipo, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :tipo, :class => 'form-control' %>
</div>
<%= error_span(#product[:tipo]) %>
</div>
<p> <hr> </p>
<%= f.fields_for :images do |builder| %>
<%= render 'image_fields', f: builder %>
<% end %>
<%= link_to_add_fields "Add Question", f, :images %>
<p> <hr> </p>
<%= f.submit nil, :class => 'btn btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
products_path, :class => 'btn btn-default' %>
<% end %>
_image_fields.html.erb
<fieldset>
<%= f.label :link, "Imagen" %><br />
<div class="col-xs-6 col-md-3">
<a href="#" class="thumbnail">
<img src="<%= Here I want to introduce the link %>" alt="...">
</a>
</div>
<%= f.check_box :_destroy %>
<%= f.label :_destroy, "Remove Imagen" %>
</fieldset>
products_controller.rb
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
before_action :build_image, only: [:edit]
private
# Use callbacks to share common setup or constraints between actions.
def set_product
#product = Product.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def product_params
params.require(:product).permit(:name, :price, :stock, :tipo, images_attributes: [ :link ])
end
def build_image
#images = #product.images.build
end
end
I have a problem at the moment with my _form.html.erb for editing a game. My code for this class is as followed:
<%= form_for #game, :html => { :multipart => true } do |f| %>
<% if #game.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#game.errors.count, "error") %> prohibited this game from being saved:</h2>
<ul>
<% #game.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<div id="p1"><%= f.label :game_name %> </div>
<%= f.text_field :game_name %>
</div>
<br />
<div class="field">
<div id="p1"><%= f.label :genre %> </div>
<%= f.text_field :genre %>
</div>
<br />
<div class="field">
<div id="p1"><%= f.label :console %> </div>
<%= f.select :console, Game::CONSOLE_OPTIONS, :prompt => 'Select' %>
</div>
<br />
<div class="field">
<div id="p1"><%= f.label :condition %> </div>
<%= f.text_field :condition %>
</div>
<br />
<div class="field">
<div id="p1"><%= f.label :description %> </div>
<%= f.text_area :description, :rows => 6 %>
</div>
<%= f.file_field :photo %>
<br />
<div class="actions">
<%= f.submit %>
<%= button_to 'Destroy', root_url, :confirm => 'Are You Sure?', :method => :delete %>
</div>
<% end %>
The problem I have is as followed. If I click the delete button it will delete the record no problem, but if I click the update button it removes the record also. If I take out the delete command then it updates fine. How can I get both to display together whilst doing their individual duties?
You need extract your destroy button from your form_for of update.