Posts by Alex Takitani • 1,060 points
52 posts
-
1
votes1
answer79
viewsA: View inside View
Rails already has this feature, it is called "Nested Attributes" https://share.atelie.software/rails-nested-attributes-com-has-many-42ecf6179871…
-
2
votes2
answers116
viewsA: How to update a CRUD with Scaffold?
This your doubt is very common for those who are starting with Rails, I’ve had the same question. Scaffold is a feature that only serves to start a basic CRUD, you use a lot at first, but then you…
-
0
votes1
answer94
viewsA: Is there any way to Take the full path to import a csv File?
You came close, using the Pry itself, you can "enter" objects, as if they were directories. You could have made cd @user.file and there have given an ls. You would see the methods that the object…
-
0
votes2
answers104
viewsA: Modelling Ruby on Rails
I would not create a table for each type of equipment, but a table of equipment. In this case, equipment has N inquiries normally.
-
0
votes2
answers44
viewsA: set shell user to call script in Rails
You can use sudo -u username
-
1
votes1
answer594
viewsA: Ruby on Rails - Upload files
There are several Gems that help a lot: https://github.com/carrierwaveuploader/carrierwave https://gorails.com/episodes/file-uploading-with-carrierwave…
-
0
votes1
answer30
viewsA: Error while trying to create a Rubyonrails controller in Windows environment using Gemfile Gem tiny_tds
You need the tinytds available on S.O. How you installed ruby? If using this distribution comes all ready to use: http://www.railsinstaller.org/pt-BR…
-
1
votes1
answer284
viewsA: What is the difference between form_for and form_tag?
form_for you use for a specific model, ex <% form_for @user do |f| <%= f.text_field :nome %> <%= f.email_field :email %> <%= f.submit %> <% end %> Form tag vc uses to…
ruby-on-railsanswered Alex Takitani 1,060 -
0
votes1
answer640
viewsA: How to pass parameter for validation/processing in the RUBY view
You put the parameter in the link: link_to backoffice_pedidos_path(type: 'open') this will give you in the controller access to a params[:type] put this in a variable, remembering to treat the case…
-
-1
votes1
answer131
viewsA: Error installing Rails on Linux Mint
Take a look at this script: https://github.com/rvm/rvm/blob/c5fce7359bed8f93a63d017f6e764d614a9967f8/scripts/functions/requirements/ubuntu RVM uses this script to install the dependencies needed to…
-
0
votes1
answer69
viewsA: Counting records updated by day Rails
Your question is a little vague, but I think this is what you’re looking for: https://github.com/ankane/groupdate…
ruby-on-railsanswered Alex Takitani 1,060 -
0
votes1
answer45
viewsA: Custom id on form button
Thus: <%= f.submit nil, class: 'btn btn-default' %>
ruby-on-railsanswered Alex Takitani 1,060 -
1
votes1
answer357
viewsA: Authentication and user permission
You don’t have to use Pundit for that if you don’t want to learn now. I imagine the user Log with the Target already, right? Therefore, a simple redirect_to root_path, error: "Sem acesso" if…
ruby-on-railsanswered Alex Takitani 1,060 -
0
votes1
answer272
viewsA: Select state city rails4
To sort by specific values you have to use a case. @cidades = Cidade.where("estado_id = ?", Estado.first.id).order("CASE id WHEN #{Estado.select(:capital).id} THEN 0 ELSE 1 END")…
-
1
votes2
answers55
viewsA: How to compare hash coming from JSON on RAILS
JWT is the way. Take a look at this post: https://www.sitepoint.com/introduction-to-using-jwt-in-rails/…
-
1
votes1
answer122
viewsA: Creating a Ruby Commitment Schedule
This code generates the output you want on the console: start = Time.new(2016, 07, 29, 8,00,0, "+03:00") end_time = Time.new(2016, 07, 29, 12,00,0, "+03:00") while(start < end_time) p "#{start} -…
-
1
votes2
answers75
viewsA: What is the best way to create a model q has a field that is an integer Enum?
Create as a whole, and then configure the model: Rails g model person status:integer http://api.rubyonrails.org/v4.1/classes/ActiveRecord/Enum.html…
-
2
votes3
answers228
viewsA: Using Services to vailidar + ruby on Rails
You can do a refactoring on this service, using 1 query instead of 2 like this: class UserService def self.create_user(user_username, user_email) return false if User.where("username =? or email =…
-
0
votes1
answer78
viewsA: Authorisation problem with Pundit
The problem is the way you’re trying to authorize the action. See this example of authorization class: class PostPolicy attr_reader :user, :post def initialize(user, post) @user = user @post = post…
ruby-on-railsanswered Alex Takitani 1,060 -
1
votes1
answer240
viewsA: How to run Javascript function on the Current page through the Application Controller?
You don’t need to Gem or go through the Rails. Place a function in your Avascripts that checks and gives the message. Using jquery is simple: http://api.jquery.com/jquery.browser/…
-
1
votes1
answer88
viewsA: Start Ruby application on boot
Using RVM, you need to create a wrapper. See how in the documentation: https://rvm.io/deployment/init-d
ruby-on-railsanswered Alex Takitani 1,060 -
0
votes2
answers162
viewsA: Problem when rendering partials dynamically
Rails knows how to find the partial of a model automatically. http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials If you have an instance of a model to render into a partial, you…
-
1
votes1
answer70
viewsA: Make condition within the surrender
Mount the hash instead: res = { 'request'=>{ }, 'response'=>lista } Add the parameters like this: res['request']['negotiation'] = params[:negotiation] if params[:negotiation]…
-
0
votes2
answers67
viewsA: Rails does not accept request
No details of what and how you’re accessing, it’s a bit of a kick, but you’re probably having trouble CORS. This Gem solves: https://github.com/cyu/rack-cors…
-
14
votes1
answer6657
viewsA: What is attr_accessor in Ruby?
The attr_accessor is a "shortcut" that creates read, write and instance variable methods in a class. http://apidock.com/ruby/Module/attr_accessor Ex.: Suppose you have a class Carro wanted to access…
-
2
votes1
answer122
viewsA: Use of STI(Single Table Inheritance) on Rails
If the models will inherit a considerable number of attributes and will implement common behavior, yes, it is a good option. Using 9.4 postgres with Rails 4.2 you can make it very transparent. I…
-
0
votes1
answer49
viewsA: SVG image conversion in Ruby on Rails
Use the Gem mini_magick https://github.com/minimagick/minimagick If you use Ubuntu, you need to have imagemagick and librsvg2-bin installed image = MiniMagick::Image.open("input.svg") image.format…
-
1
votes1
answer52
viewsA: Why does this way of using case not work?
The syntax should be: def label_file_type(type) label = case type.to_s when '.jpg', '.jpeg', '.png' content_tag(:span, 'Imagem', class: ['label', 'picture']) when '.mp3' content_tag(:span, 'Áudio',…
-
1
votes1
answer100
viewsA: Fails when I make Bundle install
Gem Debugger is not compatible with its Ruby version. Install the Gem byebug in place.
-
0
votes3
answers169
viewsA: Conditional relationships
In the case of the Department it’s simple: class Department < ActiveRecord::Base has_many :users , ->(u) { where(user_type:User.user_types[:admin]) } end In User’s case, Rails has no…
-
0
votes2
answers69
viewsA: Require files on Seeds.Rb
Use the Gem http://github.com/james2m/seedbank, it "turbine" the operation of the Seeds.
-
-1
votes1
answer136
viewsA: synchronize two screens
Websockets solve your problem. It’s a bit old, but this Railscasts explains how to implement: http://railscasts.com/episodes/260-messaging-with-faye?view=asciicast…
-
0
votes1
answer112
viewsA: I want to select a specific value in the collection_select, how do I?
Selected works with value, not text, in your case @n should have "22" as content, so it would work.
ruby-on-railsanswered Alex Takitani 1,060 -
2
votes2
answers490
viewsA: Adding more fields to the user table with Gem Devise
There is no problem, it is a table like any other. Create a Migration and add fields.
-
1
votes1
answer677
viewsA: Devise - Email confirmation and Forget password? [ email does not send ]
The error is in the gmail SMTP connection. Are you using a machine with internet access? No firewall blocking?
-
1
votes2
answers496
viewsA: Form to change variable for a calculation in the same view
You don’t do this in the view, but in the controller. Take the 2 variables as parameter, perform the calculation and return the data ready for the view.
-
3
votes1
answer152
viewsA: REST with problem in CREATE
Rails expects you to post in the format: { "company": { "name": "teste", "email": "[email protected]" } }
-
0
votes2
answers1213
viewsA: What are the advantages and disadvantages of storing session variables in the database?
The main use for bd session is when you want to share the session between more than one app. You can also use it to store more data than cookies allow (4k) As for performance, it is noticeable if it…
-
1
votes1
answer125
viewsA: Sidekiq for multiple domains
You have 2 options. Use in the same redis, using a queue for each app https://github.com/mperham/sidekiq/wiki/Advanced-Options#queues Or use a redis for each app ( obviously running on different…
-
3
votes1
answer401
viewsA: Humanize in accented characters
You can give an example of how you are using humanize? In any case, it is a problem with the UTF-8. Test on the console "É".downcase It doesn’t work while "É".mb_chars.downcase yes. Then an exit…
-
1
votes2
answers443
viewsA: How to Best Do Conditional WHERE’s with Activerecord on Rails?
Use the Gem ransack. The most "idiomatic" way to do without using Gems would be: @pessoas = Pessoa.all @pessoas = @pessoas.where("idade = ?", params[:idade]) if params[:idade]…
-
1
votes3
answers332
viewsA: Is it recommended to test model validations?
Depends on how you’re developing. If you are doing test-driven design, i.e., Red-Green-Refactor makes sense to ensure that validations exist on the model. Using Shoulda…
-
1
votes1
answer280
viewsA: Dynamic Field Forms in Rails?
Rails will receive the value of any element that: is inside the form has the name property filled, even if dynamically created. Since you are using 4.1, Strong Parameters will force you to release…
-
1
votes1
answer566
viewsA: Ruby on Rails read csv file and fill table
To format csv for AR format, use this: https://github.com/tilo/smarter_csv
-
0
votes2
answers220
viewsA: How to use a Rails cron job to run a program in Java?
Rails does not have cron job, this is the task of the operating system. And yes, you can use cron to call a program in java, as long as it is "chargeable" per command line.
-
1
votes2
answers1190
viewsA: Access local printer
The browser does not have direct access to printer, I would solve as follows: Create a desktop application, which would be installed on the client’s computer. This app would darlings in a print…
-
0
votes2
answers266
viewsA: Updating Header with Jquery after page reload
To do in Rails: <li <%="class='active'" if current_page?(sobre_path) %>> <%= link_to "Sobre", sobre_path %> </li>
-
1
votes1
answer210
viewsA: Ruby on Rails boot time
Zeus and Spring that would help with the boot time of Rails, depend on Fork that only works on *Nix systems. I recommend you migrate your development environment to linux. I started developing in…
-
2
votes1
answer83
viewsA: Problem with Gem "confirmable" module "Developer" in Rubyonrails
Make your form like this: <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> The problem lies in the route, I believe.…
-
5
votes3
answers144
viewsA: Should I use Symbols in hashes and parameters to optimize memory usage in Ruby?
There’s no difference between hash = {:indice => 'valor'} hash = {indice: 'valor'} It’s just "syntax sugar," and it only works from 1.9 up.