Overriding spree views using deface - spree

I am trying to override some view using Deface but I got this error and warning in the console:
Deface: 1 overrides found for 'spree/shared/_header'
Deface: 'header_background' matched 1 times with 'div#spree-header'
Deface: [WARNING] No :original defined for 'header_background', you should change its definition to include:
:original => '870f2cc85da3717b7c721a3e99245cf65b607a19'
Deface: [WARNING] Circular sequence dependency includes override named: 'auth_shared_login_bar' on 'spree/shared/_nav_bar'.
Deface: 2 overrides found for 'spree/shared/_nav_bar'
Deface: 'main_menu' matched 1 times with 'nav#top-nav-bar'
Deface: [WARNING] No :original defined for 'main_menu', you should change its definition to include:
:original => 'a35cdc6247d04a90fc0aefc58f068ae2b3923eab'
Deface: 'auth_shared_login_bar' matched 1 times with 'li#search-bar'
Deface: [ERROR] The original source for 'auth_shared_login_bar' has changed, this override should be reviewed to ensure it's still valid.
Deface: [WARNING] Circular sequence dependency includes override named: 'auth_shared_login_bar' on 'spree/shared/_nav_bar'.
Deface: [WARNING] Circular sequence dependency includes override named: 'auth_shared_login_bar' on 'spree/shared/_nav_bar'.
Deface: 1 overrides found for 'spree/shared/_main_nav_bar'
Deface: 'home-link' matched 1 times with 'li#home-link'
Deface: [WARNING] No :original defined for 'home-link', you should change its definition to include:
:original => '79d342a6fd7281d8499d3a5ee5480f416f733e98'
these are my overrides files:
update_ordes.rb
Deface::Override.new(:virtual_path =>"spree/orders/edit",
:name => "continue_shopping",
:replace => "erb[loud]:contains('link_to t(:continue_shopping), products_path')",
:text => "<%= link_to t(:continue_shopping), products_path, :class => 'btn btn-primary' %>")
auth_login_bar.rb
Deface::Override.new(:virtual_path => "spree/shared/_nav_bar",
:name => "auth_shared_login_bar",
:insert_before => "li#search-bar",
:partial => "spree/shared/login_bar",
:disabled => false,
:original => 'eb3fa668cd98b6a1c75c36420ef1b238a1fc55ac',
:sequence => {:after => "auth_shared_login_bar"})
update_header.rb
Deface::Override.new(:virtual_path => "spree/shared/_header",
:name => "header_background",
:replace => "div#spree-header",
:text => '<div class="container">
<header id="header" class="row" data-hook>
<%= render :partial => "spree/shared/nav_bar" %>
<%= render :partial => "spree/shared/main_nav_bar" if store_menu? %>
</header></div>')
update_menu.rb
Deface::Override.new(:virtual_path => "spree/shared/_main_nav_bar",
:name => "home-link",
:remove => "li#home-link")
Deface::Override.new(:virtual_path =>"spree/shared/_nav_bar",
:name => "main_menu",
:replace =>"nav#top-nav-bar",
:text => '<nav id="top-nav-bar" class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div id="logo"><%= logo %></div>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right" data-hook>
<li id="search-bar" data-hook>
<%= render :partial => "spree/shared/search" %>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>'
)
I also added the gem 'spree_bootstrap_frontend'
I do not get the changes done for the spree/orders/edit file
how should i fix this issue??

Original
The no original warnings are exactly what they say. You need to add the original option to your update_header.rb file. Also, your original hash value for auth_shared_login_bar is outdated and hence you need to either update that, or change to the exact original block you are using.
Sequence
Sequence option is used to know the order of overrides, when different overrides are being applied and the order matters. However, in auth_shared_login_bar, you are giving the reference of sequence to itself, causing a circular dependency. You should either remove that or give any other override this one depends on (For example :sequence => 'main_menu')

Related

Redmine Plugin Development edit form_for

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)

Searching within HTML elements in RSpec view tests

As part of my view specs, I sometimes like to check that the right text is also rendered for a certain element on the page.
Let's say the rendered HTML is -
<div class="user-msg">
<b>Thank You!</b>
</div>
I might test in my view specs as -
expect(rendered).to match(/Thank You/)
However this could incorrectly fail or pass depending on whether there's something else on the page that also says "Thank You".
How do I search within the specific <div> in question? If this were a feature test I'd use Capybara to select the node -
within(".user-mssg") { expect(page.body).to have_content("Thank You") }
How do I find a specific HTML element (e.g. .user-msg) and search within it in my View specs?
Thanks!
Edit: "Thank you!"
rspec-html-matchers does just that:
<h1>Simple Form</h1>
<form action="/users" method="post">
<p>
<input type="email" name="user[email]" />
</p>
<p>
<input type="submit" id="special_submit" />
</p>
</form>
spec:
expect(rendered).to have_tag('form', :with => { :action => '/users', :method => 'post' }) do
with_tag "input", :with => { :name => "user[email]", :type => 'email' }
with_tag "input#special_submit", :count => 1
without_tag "h1", :text => 'unneeded tag'
without_tag "p", :text => /content/i
end

rails button_to with url helper not using index/get

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?

Simple form submit button not working

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

Using dropdown selector to change paths in Rails 4

I have a dropdown selector next to a search box in my navigation bar.
<select>
<option> All </option>
<option> Ask </option>
<option> Offer </option>
</select>
<form class="navbar-form navbar-right">
<%= form_tag(i_want_to_choose_this_path, :method => :get) do %>
<%= text_field_tag :search, nil,
{:id => "search-query-2", :placeholder => "Search favors..."} %>
<%= hidden_field_tag :use_keywords, "true" %>
<%= hidden_field_tag :wide_search, "true" %>
<% end %>
</form>
How can I use the selected option to change the path the search form will route to, to either asks_path, offers_path or all_path? The options are just words that relate to the paths I want to choose. They do not exist in any models. I looked at category_select, but it seems to require that my options are related to a model, which they don't, and I'm not sure how they would, because the paths point to different models.