I have this code...
<%= simple_form_for my_object, url: object_path(object_id), html: {class: "form account-form"}, remote: true do |f| %>
<div class="row">
<div class="col-md-4">
<%= f.input :numero_matricula, label: "Núm. de Matricula" %>
</div>
<div class="col-md-4">
<%= f.input :rg, label: "Rg", required: true %>
</div>
<%= f.button :submit, class: 'btn-default', disabled: false %>
<% end %>
When i click at the submit button, the request is html, but i need to call the update.js.erb. In my applicatin.js i have this:
//= require jquery
//= require jquery_ujs
//= require icheck
//= require chosen
//= require jquery.mask
//= require jquery.maskMoney
//= require bootstrap
//= require smart_listing
//= require bootstrapValidator
//= require bootstrap-datetimepicker
//= require locales/bootstrap-datetimepicker.pt-BR
//= require editable/bootstrap-editable
//= require editable/rails
//= require_tree .
This is the controller:
class FuncionariosController < ApplicationController
respond_to :html, :json, :js
def update
#Object = Funcionario.find(params[:id])
#object.update_attributes(params[:object])
end
end
does anyone know what I'm doing wrong?
If you need more information I am available...
Related
I'm attempting to make the Froala gem work in my Rails 5.2 app and am having two issues:
The license key is not being recognized, so when I look at my live site it has an "unlicensed editor" bar. (Picture shows angry red bar and scadzillions of JS errors.)
The code editor button makes a second text box appear inside the first, rather than changing the original text to the code view. This one only shows up on the live site (Heroku), but does not happen on localhost. I suspect something could be amuck with the asset pipeline...?
The editor is rendered like this:
<%= simple_form_for(#blog) do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<div class="form-inputs">
...
<div class="form-group">
<%= f.label :body %>
<%= f.text_area :body, id: "wysiwyg" %>
</div>
...
</div>
<div class="form-actions text-center">
<%= f.button :submit, class: "btn-outline-primary" %>
</div>
<% end %>
I have the following on-page initialization of my Froala instance:
<!-- script for FROALA-WYSIWYG -->
<script>
$('#wysiwyg').froalaEditor({
key: '<%= ENV['FROALA_ACTIVATION_KEY'] %>',
inlineMode: false,
heightMin: '200px',
toolbarButtons: [
'bold', 'italic', 'underline', 'paragraphFormat', 'formatOL',
'formatUL', 'insertHTML', 'undo', 'redo', 'html'
]
})
</script>
And this is in my application.js.erb:
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require popper
//= require magnific-popup
//= require jquery-ui
//= require jquery-ui/widget
//= require jquery-ui/widgets/sortable
//= require rails-ujs
//= require froala_editor.min.js
//= require plugins/align.min.js
//= require plugins/char_counter.min.js
//= require plugins/code_beautifier.min.js
//= require plugins/code_view.min.js
//= require plugins/colors.min.js
//= require plugins/font_size.min.js
//= require plugins/fullscreen.min.js
//= require plugins/image.min.js
//= require plugins/image_manager.min.js
//= require plugins/inline_style.min.js
//= require plugins/line_breaker.min.js
//= require plugins/link.min.js
//= require plugins/lists.min.js
//= require plugins/paragraph_format.min.js
//= require plugins/paragraph_style.min.js
//= require plugins/quote.min.js
//= require plugins/special_characters.min.js
//= require plugins/url.min.js
$('selector').froalaEditor({
key: '<%= ENV['FROALA_ACTIVATION_KEY'] %>'
});
I have the recommended imports in my application.scss:
#import "bootstrap";
#import "font-awesome";
#import "trix";
#import 'bootstrap-datetimepicker';
#import "froala_editor.min";
#import "froala_style.min";
#import "font-awesome-sprockets";
#import "font-awesome";
#import 'plugins/char_counter.min.css';
#import 'plugins/code_view.min.css';
#import 'plugins/colors.min.css';
#import 'plugins/fullscreen.min.css';
#import 'plugins/image_manager.min.css';
#import 'plugins/image.min.css';
#import 'plugins/line_breaker.min.css';
#import 'plugins/quick_insert.min.css';
#import 'plugins/special_characters.min.css';
#import 'plugins/table.min.css';
And the recommended gems:
gem "wysiwyg-rails"
gem "font-awesome-sass"
I have the key listed in my secrets.yml:
development:
...
FROALA_ACTIVATION_KEY: *actual key here*
production:
...
FROALA_ACTIVATION_KEY: <%= ENV["FROALA_ACTIVATION_KEY"] %>
And my application.yml (just to be safe):
FROALA_ACTIVATION_KEY: *actual key here*
Froala support has been less than useful, just recommending that I look in my console to verify the following two queries:
$.FE.VERSION
“2.8.5”
$.FE.INSTANCES[0].opts.key
undefined
Has anyone here gotten this to work with Rails?
I was not able to get rid of the unlicensed bar either! But I found a work around just apply this styling:
.fr-wrapper div:first-of-type {
display: none;
}
I hope I could help you with your first issue.
For my ruby on rails application the destroy method doesn't work.
This is how the controller.rb looks like:
def destroy
#post = Post.find(params[:id])
#post.destroy!
redirect_to '/posts/new(.:format)'
end
The show.html.erb:
<div class="btn">
<%= link_to "Delete", :method => :delete %>
</div>
And the application.js:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
When the post url is http://localhost:3000/posts/bestpostever
and I click the delete button, I get directed to http://localhost:3000/posts/bestpostever?method=delete but that's it. The post still gets shown.
I'm a Ruby on Rails beginner, following through the Pinterest clone guide by John Elder and I'm stuck on trying to apply masonry-rails and jquery.
I'm operating on c9.io and I have installed the required gems and used bundle install.
The problem I am having is that the display of my pins are still vertical and not responsive even though there are no errors displayed in loading.
What am I doing wrong?
Here is my code:
application.css
*= require 'masonry/transitions'
*= require_tree .
*= require_self
*/
pins.js.coffee
$ ->
$('#pins') .imagesLoaded ->
$('#pins') .masonry
itemSelector: '.box'
isFitWidth: true
pins.css.scss
#pins {
margin: 0 auto;
}
.box {
margin: 5px;
width: 214px;
}
.box img {
width: 100%;
}
index.html.erb
<div id="pins" class="transitions-enabled masonry">
<% #pins.each do |pin| %>
<div class="box">
<div class= "panel panel-default">
<%= link_to image_tag pin.image.url (:medium) %><br/>
<div class="panel-body">
<%= pin.description %><br/>
</div>
<% if pin.user == current_user %>
<dsv class="panel-footer">
<%= link_to 'Edit', edit_pin_path(pin) %><br/>
<%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
application.js
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require bootstrap
//= require masonry/jquery.masonry
//= require_tree .
I finally managed to find a solution to the problem!
I just tried adding the additional lines to the application.css file:
*= require 'masonry/basic'
Adding this in is said to be optional in the textbook but they are in fact very necessary to ensure the displays work properly (in my opinion...I'm a beginner).
I have some code for attending/withdrawing from a competition:
<% if #competition.users.exclude?(#user) %>
<%= link_to 'Attend Competition', attend_competition_path(#competition.id), :method => :post %>
<% else %>
<%= link_to 'Withdraw', withdraw_competition_path(#competition.id), :method => :post %>
<% end %>
When I click on the action I go to an error page:
No route matches [GET] "/competitions/1/withdraw"
Why isn't it doing a POST request? How do I fix this?
Not sure if it effects it, but my current js is
//= require jquery
//= require bootstrap
//= require turbolinks
//= require_tree .
thanks
I'm using the assets pipeline from Rails 3.1 and I want to include some javascript files only if it's the development environment.
Example:
//= require application/jquery
//= require application/jquery_ujs
// next ones only for development environment
//= require application/badglobals
//= require application/consul
Its there a standar way of doing this? Any suggestions?
Update
Looking at the Sprockets current documentation, seems like there is not a way to do this.
Why not just require these in the view? Is it important that they are loaded in the asset? To load them in the view:
<% if Rails.env.development? %>
<%= javascript_include_tag "application/badglobals" %>
<%= javascript_include_tag "application/consul" %>
<% end %>
If you rename your application.js file (or whichever file you're calling //= require ... in) to application.js.erb, you can take advantage of require_asset. i.e:
//= require application/jquery
//= require application/jquery_ujs
<% if Rails.env.development? %>
<%= require_asset 'application/badglobals' %>
<%= require_asset 'application/consul' %>
<% end %>
Source: https://github.com/sstephenson/sprockets/issues/90