I have a button_to and trying to use it with bootstrap3 buttons so the code is as thus:
<%= button_to(groups_url, {method: :get} , :class => 'btn btn-default btn-lg') do %>
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>Group
<% end %>
I have another button here:
<%= button_to(providers_url, :class => 'btn btn-default btn-lg') do %>
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>Provider
<% end %>
Notice the difference the first one works with the {method: :get} if i take that out I get the following error cliking on the button:
param is missing or the value is empty: group
In:
def group_params
params.require(:group).permit(:name, :address, :city, :state, :groupzip, :phone, :fax, :npi, :contact, :tin, :startdate, :enddate, :changedate, :change, :notes, :billingid, :mailingaddress, :mailingcity, :mailingstate, :termedcomment, :istermed, :mailingzip)
end
I am not sure why its not getting the method get, i mean it is a index route between a post and a get. Is the do call doing something funky?
Also if I do add the {method: :get} to make clicking on the button NOT give me the error, the button then looks different?! So not sure what to do here to get it to look and work right?
Related
I'm trying to override login page in spree using deface, but I can't access the login partial using the following code
Deface::Override.new(
:virtual_path => 'spree/shared/_login',
:name => 'override login',
:replace=> "body",
:text=> "<body><h1>loin<h1></body>",
:disabled => false
)
How ever this seems not to work for some reason, in the server output I get :
Deface: 1 overrides found for 'spree/shared/_login'
Deface: 'override login' matched 0 times with 'body'
Rendered /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spree_auth_devise-3.1.0/lib/views/frontend/spree/shared/_login.html.erb (50.3ms)
Rendered /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spree_auth_devise-3.1.0/lib/views/frontend/spree/user_sessions/new.html.erb within spree/layouts/spree_application (77.4ms)
I tried multiple selectors for css in the page with no result, I noticed the login partial is located in 'spree_auth_devise-3.1.0' sub directory 'not spree_frontend-3.1.0' as the rest of them, does anyone now how to deface the login page in spree or how to reference the right path for its partial ?
If you would like to replace all body, better override partial and not use Deface. It is great tool but not when you want to do so big change.
Error means that it not found body in partial, and thats true because there is no body.
You can use only
<%= form_for Spree::User.new, :as => :spree_user, :url => spree.create_new_session_path do |f| %>
<div id="password-credentials">
<p>
<%= f.label :email, Spree.t(:email) %>
<%= f.email_field :email, :class => 'form-control', :tabindex => 1, autofocus: true %>
</p>
<p>
<%= f.label :password, Spree.t(:password) %>
<%= f.password_field :password, :class => 'form-control', :tabindex => 2 %>
</p>
</div>
<p>
<%= f.check_box :remember_me, :tabindex => 3 %>
<%= f.label :remember_me, Spree.t(:remember_me) %>
</p>
<p><%= f.submit Spree.t(:login), :class => 'btn btn-lg btn-success btn-block', :tabindex => 4 %></p>
<% end %>
I am currently developing a redmine Plugin,
so far it went well. But since I integrated the plugin into a project i cant use form_for to create an edit view.
Edit View:
Formular
<div class="box tabular">
<div class="splitcontent">
<div class="splitcontentleft">
<%= form_for (#customer) do |f| %>
<div class="splitcontent">
<div class="splitcontentleft field_name">Name </div>
<div class="splitcontentright"><%= f.text_field :name, :size => 20, required: true %></div>
</div>
</div>
<hr />
<%= render :partial => '/inventory_customers/form_custom_fields' %>
<div></div>
</div>
<div><%= f.submit submit_text %></div>
<% end %>
Controller
before_filter :find_project
...
def edit
#customer = InventoryCustomer.find(params[:id])
end
...
private
def find_project
# #project variable must be set before calling the authorize filter
#project = Project.find(params[:project_id])
end
def customer_params
params.require(:inventory_customer).permit(:name, :sap_id, :sap_name, :address, :partner, :partner_text, :active)
end
Error Message
Started GET "/redmine/projects/inventory development/prototyp/inventory_customers/3/edit" for 172.20.1.197 at 2016-08-03 16:07:45 +0200
Processing by InventoryCustomersController#edit as HTML
Parameters: {"project_id"=>"inventory-development", "id"=>"3"}
Current user: COAH (id=38)
Rendered plugins/prototyp/app/views/_inventory_menu.html.erb (0.7ms)
Rendered plugins/prototyp/app/views/inventory_customers/_form.html.erb (1.6ms)
Rendered plugins/prototyp/app/views/inventory_customers/edit.html.erb within layouts/base (2.9ms)
Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.3ms)
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"inventory_customers", :id=>nil, :project_id=>#<InventoryCustomer id: 3, name: "blub", partner: false, sap_name: "asdasd", address: "sadasd", active: true, sap_id: "">} missing required keys: [:id]):
2: <div class="box tabular">
3: <div class="splitcontent">
4: <div class="splitcontentleft">
5: <%= form_for (#customer) do |f| %>
6: <div class="splitcontent">
7: <div class="splitcontentleft field_name">Name </div>
8: <div class="splitcontentright"><%= f.text_field :name, :size => 20, required: true %></div>
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
If i remove the form_for i can load the edit view but then i dont see a way to edit the object.
Since i just started with rails and redmine i have absolutly no idea how to fix the error or how i can do a work arround.
Use form_tag(path, :method=> 'put', :multipart => true ) do instead of form_for
path is something like customer_path.
Make sure to use another path for editing (singular) than for creating (plural, no id needed)
In my Rails app, the labels for the fields on the login page are way too close to the fields themselves, making it look cramped. I want to add space between them, but am not sure how.
I have Rails 4 with simple_form, bootstrap 3, and devise installed.
This is my app/views/devise/sessions/new.html.erb code:
<div class="row">
<div class="col-xs-4">
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name), html: {class: "well"}) do |f| %>
<fieldset>
<legend>Log in</legend>
<%= f.input :email %>
<%= f.input :password %>
<% if devise_mapping.rememberable? -%>
<div class="field">
<%= f.input :remember_me, as: :boolean %>
</div>
</fieldset>
<% end -%>
<div class="actions">
<%= f.button :submit, "Log in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
</div>
<div class="col-xs-8">
<h2>Signing in is easy and secure</h2>
</div>
</div>
And here is the entire github repo: https://github.com/yamilethmedina/wheels_registration
I've been looking in my bootstrap.css file and can't find relevant classes. What do you think I should do next?
You could add your own label with space after the custom label.
<%= f.input :email, label: 'Email ' %>
<%= f.input :password, label: 'Password ' %>
Or you could use tools like chrome dev tools to inspect the label element to see what class the labels are given and then add some custom css. example .label-class { margin-right: 10px; }
somehow my form is not working and I dont know why. Heres my code:
<%= simple_form_for #cr, url: edit_cr_path do |f| %>
<hr>
Design Office Involvements<br>
<%= f.collection_check_boxes :design_office_ids, DesignOffice.all, :id, :sub, {:item_wrapper_class => 'checkbox_container'} %>
<hr>
Procurement Involvements<br>
<%= f.collection_check_boxes :procurement_ids, Procurement.all, :id, :sub, {:item_wrapper_class => 'checkbox_container'} %>
<hr>
Installation Involvements<br>
<%= f.collection_check_boxes :installation_ids, Installation.all, :id, :sub, {:item_wrapper_class => 'checkbox_container'} %>
<hr>
<div class="row">
<div class="col-md-6">
Assessment Status
<%= f.input :assessment_status, :collection => [['Impacted','Impacted'],['Not impacted','Not impacted'],['Under assessment','Under assessment'],['New','New']], label: false, selected: ['New', 'New'] %>
</div>
<div class="col-md-6">
<div style="float: right">
<%= f.button :submit, 'Save' %>
</div>
</div>
</div>
<br>
<% end %>
Controller methods looking like this:
class CrsController < ApplicationController
def edit
#cr = Cr.find(params[:id])
end
def update
#cr = Cr.find(params[:id])
#cr.update_attributes(cr_params)
redirect_to edit_cr_path(#cr)
end
private
def cr_params
params.require(:user).permit(:id, :assessment_status)
end
end
And routes like this:
EndToEndManagement::Application.routes.draw do
get '/cr/:id', :to => 'crs#edit', :as => 'edit_cr'
put '/cr/:id', :to => 'crs#update'
patch '/cr/:id', :to => 'crs#update'
end
And thats the html code rails makes of my submit button:
<div class="col-md-6">
<div style="float: right">
<input class="btn" name="commit" type="submit" value="Save" />
</div>
</div>
I think the submit button is not correctly attached to the form but I tried to move it and clear some divs but nothing worked.
Best regards.
EDIT:
Thats what I tested
Removed my routes in routes.rb and replaced it with resources :crs and changed my first line in the form to <%= simple_form_for #cr do |f| %>. Didnt work!
Changed my simple_form to normal form. Didnt work!
Wrote a whole testapp with a scaffold and this form an it worked but I dont know why so I added part by part to my actual app and nothing made it working.
Found my mistake! Not that it would be so mind blowing but I will still post it :D
Had this small mistake in my application.html.erb
<div style="font-size: 1.3em"
<%= yield %>
</div>
Changed it to:
<div style="font-size: 1.3em">
<%= yield %>
</div>
And now it works fine.
It does not seem as edit_cr_path is the right url to go when you're trying to save a form.
You'll need another route:
post '/crs', :to => 'crs#create'
In your view, you probably won't need the url option as Rails can infer just looking at the object.
<%= simple_form_for #cr do |f| %>
But your object needs to be a new instance coming from your controller:
class CrsController < ApplicationController
def new
#cr = Cr.new #or whatever else to initialize the object
end
def create
#save the instance here
end
I'm a new Rails developer and this my first question here so please be gentle.
I've been using Twitter Bootstrap in my application to put tooltips and Glyphicons on buttons on my CRUD links as follows:
Show:
<%= link_to master_group, class: "btn btn-default", data: {toggle: "tooltip", placement: "left"}, title: "Show" do %>
<span class="glyphicon glyphicon-search"></span>
<% end %>
Edit:
<%= link_to edit_master_group_path(master_group), class: "btn btn-default", data: {toggle: "tooltip", placement: "left"}, title: "Edit" do %>
<span class="glyphicon glyphicon-pencil"></span>
<% end %>
Destroy:
<%= link_to master_group, method: :delete, data: { confirm: 'Are you sure?',toggle: "tooltip", placement: "left" }, class: "btn btn-default", title: "Delete" do %>
<span class="glyphicon glyphicon-trash"></span>
<% end %>
Would it be possible make my own versions of link_to, so I could just change the path in each call, for example:
link_to_show master_group
link_to_edit edit_master_group_path(master_group)
link_to_destroy master_group
I was trying to follow the Rails DRY principles and found myself repeating this code for each view. I was also conscious that if for example, I wanted to change the tooltip, I'd have to do it on every single view. It would also allow me to be certain that my application had good uniformity.
Could anyone help me please.
Thanks in advance.
Create your custom link_to(s) in ApplicationHelper
Example
module ApplicationHelper
def link_to_show(path)
link_to path, class: "btn btn-default", data: {toggle: "tooltip", placement: "left"}, title: "Show" do
'<span class="glyphicon glyphicon-search"></span>'.html_safe
end
end
end