How can I check the authorization in Cancancan in Ruby on Rails each time the user calls that action? | Fixed issues |
- How can I check the authorization in Cancancan in Ruby on Rails each time the user calls that action?
- How do I install masonry or other javascript in rails? (not using gems)
- How to redirect user to his profile using unique link in Rails?
- When to use a model vs. an enum?
- Using omniauth-google-oauth2 gem in rails 2.3.8 and ruby 1.8.7
- Passing ID from one controller to another
- Rails Association working only one way
- Rails: when do we must put :: before some classes for rails understand base class
- Rails passenger not working with apache
- how to get data from two different join tables
- Patch request in Backbonejs
- <%= content_for :my_region_name do %> in Phoenix/Elixir
- current_page? isn't working with routes with optional params
- Build QR code and display image without saving
- Activemerchant, checkout paypal sandbox express: transaction errors Internal Error, 10001
- How to configure apache in local development in rails
- (Mathematical) optimization in Ruby
- How rails do nested form in one form?
- What Rails-ActiveRecord association to use for this?
- Unicorn Error log
- Why generate scaffold won't work?
- SystemStackError: stack level too deep caused by Nokogiri
- heroku: lookup_asset_for_path on heroku (Rails 5)
- load a mesh with three.js in ruby on rails
- Rails 4 - Rolify - how to assign a scoped role
- display a corresponding button and it's link in rails
- vue.js and rails erb: How to place v-model tag inside erb input
- Rails: ruby class name must base on file name?
- Rails One-to-one Child Attribute Accessed as Self Attribute
- How to filter search results in rails
Posted: 07 Aug 2016 07:41 AM PDT I'm using Ruby on Rails 5 and I want that depending of the role of a User, the user can post 5 Posts or 10 or 15, and that is just a part of the several possible situations that I have to check for Authorization (for things that are not Posts for instance I have other situations that are a bit more complex), so I started using Cancancan (v 1.15.0) few days ago to don't make the User model too huge, so this way I have one class for each Role and in ability.rb I just merge the classes depending on the Role. The problem is that using Cancancan apparently it checkes the Authorization only once. For example in Creating a Post, In Post#create the first line of code is: In the Role class of the user, I have this code: I have some tests with RSpec and I see the first time the current_user (the one with that specific role) creates a Post using the controller (I mean, not by FactoryGirl or any other way that is not using the controller), it appears in log/test.log: But neither the Else nor the If appears ever again in the log, it doesn't matter how many Posts I create by the Controller, it only evaluates this condition the first time and the User get authorized to creates as many Posts as he wants because the first time the condition in the If is true and it is not evaluated each time the method create of the controller Post is called. What can I do? Thanks! :) |
How do I install masonry or other javascript in rails? (not using gems) Posted: 07 Aug 2016 07:37 AM PDT I wanted Masonry for my Rails 4.2 project and initially installed it via the masonry-rails gem and then wasted an evening until I realized that the gem was using an outdated version of Masonry. This will be my first attempt to add javascript to my Rails app without a gem. From the installation docs the options are: Download, CDN, Package managers (bower/npm) I used CDN by simply adding to the top of my index.html.erb view file that will use the script. Is this correct? What is the advantage/disadvantage of using CDN instead of Download or Package managers and if I want to add |
How to redirect user to his profile using unique link in Rails? Posted: 07 Aug 2016 07:24 AM PDT I have a Rails app using mongodb. I have a model Bot with an attribute link (string). I want user to redirect to its profile using unique link which consists of host and link (e.g. http://localhost:3000/bots/home/06b5f629b3fbec5612ef79dd14d8d762). routes.rb bots_controller.rb So I try to retrieve this unique value from request and match it to link attribute of the Bot in db but it doesn't work. |
When to use a model vs. an enum? Posted: 07 Aug 2016 07:13 AM PDT I have a |
Using omniauth-google-oauth2 gem in rails 2.3.8 and ruby 1.8.7 Posted: 07 Aug 2016 07:32 AM PDT How to do authentication using omniauth-google-oauth2 gem in rails 2.3.8? I have installed omniauth-google-oauth2 gem of version 0.1.15. But i dont know how to proceed further. |
Passing ID from one controller to another Posted: 07 Aug 2016 05:50 AM PDT So I am developing a job portal website, and I am looking to pass the current job ID over to the "job applications" controller #new method, but I am having issues being able to do so. So when a user clicks the "Job_applications#new", It gets the current page job_id. Models In my Job_Applications Controller In my View I have the following code I know I am doing something stupid here, Ideally, I would like to pass the job id without it being in the URL Example However this method shows this Any help greatly appreciated |
Rails Association working only one way Posted: 07 Aug 2016 06:47 AM PDT My model "Preconditions" creates relationships between records in the "Assignments" model, so that one assignment can be a pre-requisite for another assignment. In the console, Assignment.find(3).preassigns outputs the second record from the Assignment table, as I expect. However, the inverse is not working. Assignment.find(2).mainassigns returns an empty set. precondition.rb assignment.rb Based on similar questions, I've tried adding a polymorphic tag in the Preconditions table, like so: This caused an error, but the log suggested that I try a source_type, so I tried adding that to the assignments model, like so: But that resulted in an SQL column not found error. Thank you in advance for any insight. |
Rails: when do we must put :: before some classes for rails understand base class Posted: 07 Aug 2016 06:19 AM PDT In Ruby, I understand that When I run, I meet exception:
As I understand, Rails understand that So my question is: when we don't need to use Thanks |
Rails passenger not working with apache Posted: 07 Aug 2016 06:13 AM PDT I am trying to run rails using passenger and apache2 to I have followed everything but I am getting this problem. I don't know how to fix it my apachecof file is like this: And my rbenv path is like this: I don't know what it the problem please help me fix this issue. |
how to get data from two different join tables Posted: 07 Aug 2016 04:22 AM PDT i have two Join table first one between |
Posted: 07 Aug 2016 04:03 AM PDT I am trying to partially update an model using patch request. I wrote like this: But the server is returning a 405 error. I couldn't figure out the reason, can anyone help? My backend is a rails application. Thanks |
<%= content_for :my_region_name do %> in Phoenix/Elixir Posted: 07 Aug 2016 03:54 AM PDT How can I define a named render region in an layout? This defines a default region which I can overwrite in a child view: But I want to create multiple |
current_page? isn't working with routes with optional params Posted: 07 Aug 2016 03:45 AM PDT Here's the route: Now if I'm at then that something isn't being done. If I remove the parenthesis around |
Build QR code and display image without saving Posted: 07 Aug 2016 03:22 AM PDT I want to build QR Code of a particular string/url. After building, without saving I want to display the display the image. I don't want to persist the image. Something like Platform : Ruby on Rails 4 Thanks. |
Activemerchant, checkout paypal sandbox express: transaction errors Internal Error, 10001 Posted: 07 Aug 2016 02:51 AM PDT I try test paypal sandbox checkout.
But when I check 2 account sandbox, both tell status 'Success' |
How to configure apache in local development in rails Posted: 07 Aug 2016 02:41 AM PDT I am trying setup a loacl domain on my pc for that I have apache server install I want to open my rails s inside this abcd.com instead of 127.0.0.1:3000. In my host I have changed host file like this: But when I am trying to open abcd.com with this command I am getting this message: When I stop apache it works on localhost any help |
(Mathematical) optimization in Ruby Posted: 07 Aug 2016 03:30 AM PDT I am trying to build in an algorithm in my Ruby program that optimizes an objective function subject to a certain restricted set of values that my 'unknown' can take. The function should take the objective function, the upper limit the lower limit and return the value for 'x' that maximized the objective function within this range. If I would like to do something similar in R I can simply use a function such as optim (https://stat.ethz.ch/R-manual/R-devel/library/stats/html/optim.html). But I don't want to use R in this case neither want to use a gem that creates an R interface. Is there any gem to perform such operations directly in Ruby (maybe even for multiple unknown variables)? Edit: The reason I don't want to use an R interface is because I want to be able to deploy the application without having to install anything, such as R or GLPK on the server |
How rails do nested form in one form? Posted: 07 Aug 2016 04:43 AM PDT The scenario is that, I want to design a I usee However how to I create this in form? I thought about dynamic nested form, but I don't want there're a lots of form, I wish there would be only one input and do the same thing with dynamic nested form. Here is the github, please let me know if I need to provide more information. |
What Rails-ActiveRecord association to use for this? Posted: 07 Aug 2016 02:49 AM PDT Let's say I have a computer model. This computer has 2 characteristics:
How would these characteristics be associated with the Computer Model? (Ex: belongs_to, has_one,yadda yadda) |
Posted: 07 Aug 2016 12:57 AM PDT I am trying to deploy my rails app to digitalocean with postgresql database . my database.yml looks like this i did rake db:create and it shows myorganicmantra_production already exists but when i am restarting unicorn server and loking to unicorn.log there is line like ] and eventually it is shwing 504 timeout on the webpage here is my /etc/default/unicorn file |
Why generate scaffold won't work? Posted: 07 Aug 2016 12:45 AM PDT I'm currently following Rails tutorial by Michael Hartl here. To proceed with my application I did the following(as the book said): However I'm getting the following errors: |
SystemStackError: stack level too deep caused by Nokogiri Posted: 07 Aug 2016 12:48 AM PDT I'm trying to call document.at_css("a[data-field=url]") on a web page but I'm getting SystemStackError. I'm aware that this is caused by overflowing the memory stack but I have no idea how to solve this. Following is my stack trace, |
heroku: lookup_asset_for_path on heroku (Rails 5) Posted: 06 Aug 2016 10:26 PM PDT Gem file: application.html.erb config/application.rb config/environments/production.rb Command: precompile assets
|
load a mesh with three.js in ruby on rails Posted: 06 Aug 2016 10:08 PM PDT I am trying to map a load a mesh into my three.js animation in my ruby on rails project. I use the following code: But somehow its not doing anything. The cube.js file is in my assets/images folder. Am I using the paths wrong? If i just load a sphere like following it works just fine. |
Rails 4 - Rolify - how to assign a scoped role Posted: 07 Aug 2016 01:27 AM PDT I'm trying to figure out how to assign a role to a user in Rails 4, using rolify. My use case is: I want to assign global roles to users who operate the app. I want to assign scoped roles to all customers. Each customer belongs to an organisation. Any role they are assigned will be confined to the organisation they belong to. How can I achieve this in rails? At this stage, I'm stuck with the logic of how to do this. |
display a corresponding button and it's link in rails Posted: 07 Aug 2016 12:05 AM PDT I have a structured layout here in Rails 5 ERB that renders a partial for each data passed in as locals via a json file for data, but each of them either has 1 or 2 buttons with it's corresponding links inside, I also want to change the button's title for each link it corresponds to. I've already implemented it but I feel that putting all the logic in the view is kind of unappealing is there a way that i can put this in a helper that displays a specific button for each of their links inside of the json file? I basically want to achieve this data.json
index.html.erb controller/template _panel.html.erb /partial |
vue.js and rails erb: How to place v-model tag inside erb input Posted: 06 Aug 2016 10:05 PM PDT I am currently trying to include a vue.js v-model into my erb form input tag and I cannot find the right syntax. Here is how my code currently looks: I would very much appreciate any idea here. Thanks! |
Rails: ruby class name must base on file name? Posted: 06 Aug 2016 11:16 PM PDT I'm learning
If I don't follow those convention, when compiling rails will throw exception. I don't see those conventions on those library github pages. Will this true for whole rail project, with all libraries ? |
Rails One-to-one Child Attribute Accessed as Self Attribute Posted: 07 Aug 2016 12:11 AM PDT It's been a few year since I did any Rails development. There used to be a way to access a child attribute, in a one-to-one relationship, as that model's attribute. So for instance, if you had two models: This used to be easy to do when you could explicitly define the accessible attributes in the model. It seems this is gone now in Rails 4. Any ideas? |
How to filter search results in rails Posted: 06 Aug 2016 08:40 PM PDT Im using searchkick to search my database and I have the initial search working, but I want to have the user able to select from categories to further refine the search results. Right now everytime I search it is searching all the recipes and doesnt maintain previous results. Im using links to apply the filter and not resubmitting a form which is what most examples I find are doing. Heres my index from my controller: Which that calls a different class (to keep controller clean) which calls this for the search function: The where and order just add to the constraints and those work fine. I know I need to change the "Recipe.search" part to call search on the old list (if thats even possible) or modify the query variable to include the old params but not sure how to recall those. |
You are subscribed to email updates from Newest questions tagged ruby-on-rails - Stack Overflow. To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States |
No comments:
Post a Comment