theshashiverma
Joined
Activity
I am creating an admin template, and there is a customizer section in which I have created 3 radio buttons (named: Red, Blue, Green). There is a left sidebar navigation menu and I want to change the background color of sidebar navigation menu by clicking on the radio buttons. If I am clicking on the button it is changing the bg-color of sidebar navigation menu by adding a class, but if I am going to another page gets reloaded and the class gets removed.
I have tried one thing, in my application_helper.rb I have added the following code
def is_active(action)
@color = "red"
params[:action] == action_name ? @color : nil
end
and in my layouts folder, I have a partial file _sidebar.html.erb and at the outer div I am using this helper like below
<div class="sidebar-nav <%= is_active('action_name') %>" id="collapse-sidebar" >
What I am doing here is, checking the action name if it is matching then adding a class red which is stored in an instance variable @color
If I can pass the value of the radio button to the application_helper file dynamically means if I click on red the value should be red, green then the value should be green. and by which I can change the class name dynamically in application helper and further that would change the color of the sidebar.
Please, If I am doing anything wrong or it's is not the right way to do this or we can't achieve this kind of functionality in ruby on rails, please acknowledge me, that would be appreciable.
On stackoverflow:
https://stackoverflow.com/questions/55808182/how-to-pass-the-value-of-input-type-radio-in-application-helper
Thank you
I am getting this "Rails ExecJS::ProgramError in Pages#home" error in browser, when i go to the root path which is pages#home. I am using windows 10. untill i dont add the bootstrap it works fine but after adding bootstrap and jquery i get this error . I follow this article to add bootstrap in my project https://www.rubydoc.info/gems/bootstrap/4.2.1
AND WHY I AM GETTING THIS ERROR ? WHILE USING UBUNTU I DID NOT FACE THAT BUT WHY IN WINDOWS(10)?
Thanks for the reply sir, Please give it a read here i have elaborate my question in more details.
I am creating an admin template and i am giving an e-commerce section in the template. Firstly I build the project using ROR then I add auth using Devise and now I have added the e-commerce section using Spree. And for that, I Followed https://github.com/spree/spree
and when I use this command rails g spree:auth:install
it removes all the config settings of devise.rb that I have made for the devise (i followed this for devise setup https://www.sitepoint.com/devise-authentication-in-depth/) and remains only one line Devise.secret_key = " key value "
This is what I have done till now.
And suppose if person 1 buys my template and use to sell mobile phones and person 2 who also buy my template and used to sell clothes. SO HOW MY TEMPLATE DIFFERENTIATE BOTH THE BUYERS. Is there would be any specific key for both the buyers if yes how they would generate it
I am working on Ruby on Rails project, and I have already added the devise authentication,
and now I have added the spree in my project by following this Github/spree
I want to know that is there any secret key for the spree that makes it unique.
For example, if person1 is using my project and he sells mobile phones and person2 is also using my project and he sells clothes, so does the products of both the users will be shown on their websites, I mean person1's products will be shown on person2's shopping website or vice-versa, or is there any unique key that differentiates both's websites.
I have been googling about it for many hours and I found the device's config.secret_key but if I made any changes in the key or remove the key project still works.
Thank you
Thank you for the reply sir, yes, I am using 5.2 and you have tell me the new way to keep the secrets and id of providers, I will try to attempt like this.
but, now what i did, I kept the id and secret in devise.rb file and that was also working fine, and now I am suffering from another issue that is how to add multiple provider . can you please check this out https://github.com/plataformatec/devise/issues/5017
and I have one more thing to ask : few days ago I read an article on internet that in upcoming rails6 we are going to use some kind of webpack or webpacker and then we dont need to use the coffeescript in our project or may be it would not be compulsory to use the coffeescript anymore. and it will be fine if we use js. Is it right ? because in project i have used almost coffeescript.
Thank you so much.
@ChrisOliver Thank you sir for the reply, one more thing to ask,when i am using omniauth+devise, is it necessary to keep the client id and secret in the .env(environment variable) file because for that i have to install a dotenv gem and then to run the project i have to run "dotenv rails server" command. Can I keep the id and secret in omniauth.rb file which is customly created by in the initializer folder?
I want to add social authentication in my project like user can also login with Facebook, Github, and Google.
I have already added the simple authentication with the devise gem. And now I want to add the social authentication also.
I found many articles on the Internet and I majorly found two way to do that
devise + omniauth
omniauth
So, can anyone suggest me what is the best way to have social authentication
This is the article of omniauth https://richonrails.com/articles/google-authentication-in-ruby-on-rails And this one is of devise+omniauth https://scotch.io/tutorials/integrating-social-login-in-a-ruby-on-rails-application that I followed.
Thank You.
I have a view file index.html.erb in my view folder and there I am showing some data in the form of Table(bootstrap table) and this is a static table so I had to write so many lines of HTML for this table.
Now, I want to a show the data in Table in a dynamic form, means I want to keep all the data in a JSON file and want to parse that data in my view file and fetch all the data by having a loop over it so I just have one block of HTML and all the table data should create through that block of code.
Or is there any other method to do this means getting the data dynamically in ruby on rails?
I did google, but everywhere I found this with ruby, but I don't know how to do this in rails, I followed this https://hackhands.com/ruby-read-json-file-hash/ in .erb file this does not work, it works only with .rb file.
Please If you have any tutorial suggestion give me the link.
I am working with CoffeeScript in Ruby on rails. And I am using http://js2.coffee/ to convert my javascript and jquery into CoffeeScript.
We know, Ruby on Rails provides us by default .coffee files when we create any controller.
In my view folder, I have defined a test.html.erb file, I have a button
<button id="p">try</button>
and if I define the script for this button by using javascript or jquery in the same page i.e. test.html.erb it works.
My javascript code
document.getElementById("p").onclick = function() {myFunction()};
function myFunction() {
alert("hello");
}
and my jquery
$(document).ready(function(){
$("#p").click(function(){
alert("hello");
});
});
And now I have created a custom file in app/assets/javascripts/test.coffee
coffeescript of my jquery code
$(document).ready ->
$('#p').click ->
alert 'hello'
return
return
and when I use this in my test.coffee it works fine.
coffeescript of javascript code
myFunction = ->
alert 'hello'
return
document.getElementById('p').onclick = ->
myFunction()
return
and when I use this code in my test.coffee it shows error in my console
Uncaught TypeError: Cannot set property 'onclick' of null
I have also try the test.js.coffee but still get the same error
so should I only use the coffeescript generated by jquery or is there any way to use the coffeescript generated by javascript?