How can I destroy a record in a join table with has_and_belongs_to_many association? | Fixed issues |
- How can I destroy a record in a join table with has_and_belongs_to_many association?
- Description not available because of robots.txt on rails app
- How to resolve relations in a query for JSON
- Sending mail, getting ActionView::MissingTemplate <path> with 'mailer'
- Route all subdomains to my Heroku Rails app
- Random No route matches [GET] "/" error with a working root_path
- Getting error Faraday::ClientError: the server responded with status 400 on adding a share to linkedin in rails
- DRY views strftime call
- has_many after a has_many :through?
- Fullcalendar rails: wrongly displaying events sources
- How to select new_station where ST_DWithin(PostGIS) in rails
- Rails Form: How to handle multiple selections in drop-down menu
- How to send reset password instead of confirmation email in Devise?
- JSON to insert in Rails
- How to integrate a bootstrap file with existing Rails application in cloud 9? [on hold]
- How to generate a html file from a template in a controller and upload it via paperclip in Rails 4
- Rails Paperclip upload not working AWS
- Devise: Add User Details in different table
- Updating the values on Many-to-Many relationship table
- raise ActiveRecord::PendingMigrationError if ActiveRecord::Migrator.needs_migration?
- How to temporarily disable Omniauth authentication in Rails?
- Extending an ActiveRecord Polymorphic Association with JOIN statements?
- How does Rails View Helper work
- How to stop rspec from dropping the test database before tests
- Rails 5: Table name not being inferred through class_name
- Can we create Ruby on Rails API-only Application with ActionCable Live updates?
- Nginx + Phusion Passenger + Rails = staging ENV won't be set
- Rails sending a dynamic content and layout to action mailer
- how to submit rails form once with validation check if only all fields are valid
- Questions about Fat-Model, Skinny-Controller practice
How can I destroy a record in a join table with has_and_belongs_to_many association? Posted: 25 Oct 2016 07:45 AM PDT I am creating an app where a user can favorite a room. I accomplished this with a has_and_belongs_to_many association. I chose this instead of has_many :through because this requires a third model (which could be Favorite) and it would only be used to create the association. How can I add a unfavorite(destroy) action into the view or controller? rooms_controller.rb routes.rb show.html.erb (room) wishlist.hmtl.erb |
Description not available because of robots.txt on rails app Posted: 25 Oct 2016 07:39 AM PDT I have some problems with the google snippet description of my rails app in google search results. I get : I dont understand why I am getting this. I am not blocking the googlebot. Here's my robots.txt and I also include this meta in my application.html file : Why does google not want to take into account my description ? UPDATE : when I am using this tool to see if my description is displaying, it works : https://totheweb.com/learning_center/tool-test-google-title-meta-description-lengths/ but when I try to find the website via the classic google search, I still get A description for this result is not available because of this site's robots.txt |
How to resolve relations in a query for JSON Posted: 25 Oct 2016 07:47 AM PDT I have 2 tables, Jedis and Padawans, with a many to many relationship through a third table, Apprenticeship. their app/models rb files define their relations like this: Jedi: Padawan: Apprenticeship: When I query like this: And return the results to the front-end as JSON: The JS ajax call that initiated the request receives an array of objects, each representing an apprenticeship record. Each object looks like this (stringified): At this point in the process, I would prefer the apprenticeship records to be this instead (with ids resolved to objects): What is the correct, cleanest method of accomplishing this using only Ruby - so JS can receive the proper array of objects to work with? Thanks for your help. |
Sending mail, getting ActionView::MissingTemplate <path> with 'mailer' Posted: 25 Oct 2016 07:29 AM PDT When trying to send emails with Sidekiq, I am getting this error
In the controller In campaign_mailer.rb
Note: I have tried everything I can find, even re-generated mailers. It seems to work with a new mailer when I send with |
Route all subdomains to my Heroku Rails app Posted: 25 Oct 2016 07:39 AM PDT I register my domains with DNSimple. My app is hosted on Heroku. How can I arbitrarily route all subdomains to my Heroku app? Example
No matter what the user types as the subdomain (always just 1 level deep) I want it routed to my heroku app. Ideally I don't want to define every single subdomain in Heroku or DNSimple... it should just direct everything. Any and all subdomains are just routed to my app where I handle the logic of what to do with Will having these "foul" up what I am trying to do (below) Thanks! |
Random No route matches [GET] "/" error with a working root_path Posted: 25 Oct 2016 07:29 AM PDT I randomly see a No route matches [GET] "/" error in the logs of an app. Here is the output. The app is private and used by a really small number of people and none of the users have experienced this error ( not able to access the root_path ). I never see it outside the logs. I assume this could be a bot doing a scan. The And the rake routes output seems normal:
At this point the app is regularly used and this bug is just a glitch in the logs nothing more. But I think it worth asking! Any idea about what can cause this error and how or if I can do something about it? |
Posted: 25 Oct 2016 06:48 AM PDT I am trying to add a share using linkedin-oauth2 gem and getting an error I have also tried from irb but still getting same error. I have w_share permissions set for my access token but I don't know why I am getting this error. Here is a snippet of what m doing in my controller method-> Please tell me if something is wrong with my syntax or anything else and please provide the syntax for using 'add_share' method with all other options. Thanks |
Posted: 25 Oct 2016 07:40 AM PDT I have a view of my model with many date fields rendered. What I want to do is call Any ideas on how I can to DRY this? I tried to make Update: I defined this method: So I can: |
has_many after a has_many :through? Posted: 25 Oct 2016 06:34 AM PDT Here are my current models... What I want to be able to do is get all the I can get the artists easily (
Would love to be able to do something like |
Fullcalendar rails: wrongly displaying events sources Posted: 25 Oct 2016 06:24 AM PDT I've fullcalendar working in Rails with postgresql. I've a model 'Event' with which i'm trying to feed the calendar using eventSources. The problem is that when the calendar is displayed shows the events with the current date and time, not with the corresponding time and date of the events. I've been looking at these questions, which I think is related to my problem. But I have not found how to fix it yet. The code that I have so far: Event controller JavaScript I must confess I am new to Ruby, so it may be that I'm missing something basic (most likely). Thanks! |
How to select new_station where ST_DWithin(PostGIS) in rails Posted: 25 Oct 2016 05:51 AM PDT My table is I want to use Example code result name:Wall St, Broad St and Nassau St but I use in ruby on rails it error PG::InvalidParameterValue: ERROR: Only lon/lat coordinate systems are supported in geography. : SELECT name_station FROM infomaps WHERE ST_DWithin(lonlat, ST_GeomFromText('POINT(20 100)',26918), 100); How to use ST_DWithin and others PostGIS functions in rails |
Rails Form: How to handle multiple selections in drop-down menu Posted: 25 Oct 2016 05:41 AM PDT I've been playing around with my form where I have a drop-down menu where you can select multiple options: But I'm so confused at what the heck this thing is putting into my hobbies attribute (which is a string). When I print out the contents after selecting the first three options: I get this junk: So clearly it's getting the '1', '2', and '3' that I selected, which is good. But the rest of the output is weird looking. All that I want to do is be able to print '1', '2', and '3' (or whatever options were selected). Of course, I could parse these values out of the giant string based on it's dash-separated format, but that seems the wrong way to do it. I saw something about turning "hobbies" into an array by making it "hobbies[]", but that gives the odd error: So how exactly am I supposed to handle this stuff internally? |
How to send reset password instead of confirmation email in Devise? Posted: 25 Oct 2016 05:36 AM PDT I am trying to make it so that if a one type of User is created - then instead of sending the confirmations email, it sends the reset password link (I have already achieved so that the reset password link serves as both confirmation and reset password). This is basically a try to avoid duplication of emails since I allow creating a user without password so that the user then can request his first password via reset password. I am trying to override the Confirmations Controller like so: And in routes: The overriding works with other models. But the create action in confirmations controller is never called. I put a lot of But when I check the stack trace, it looks like it's called from some labda function. The question: why isn't devise using Thanks a lot! |
Posted: 25 Oct 2016 06:47 AM PDT I'm new to Rails. I need to insert the JSON response into my database. The response received is: address is a separate table. How can I get: so I can insert in the database? I did: It outputs: |
How to integrate a bootstrap file with existing Rails application in cloud 9? [on hold] Posted: 25 Oct 2016 05:18 AM PDT I have an exciting Rails application in cloud 9 and a bootstrap file in my laptop. I want to integrate the bootstrap file with the rails application in cloud9. |
How to generate a html file from a template in a controller and upload it via paperclip in Rails 4 Posted: 25 Oct 2016 05:11 AM PDT I appreciate my question should be divided in two, however both are too intimate related not to have them together here. Please note that I'm using Ruby 2.3.1, Rails 4.2.7 and Mongoid 4. I need to generate a HTML file from a template and upload it to S3. In my App I'm already using Paperclip, so I'm sticking with it, if possible. I know that ideally I shouldn't mix views within controllers, but it seems in this case, I have no alternatives. In my Model I have the following: In my controller I have the following: Now, the problem with the above is the following: 1) the file is currently being saved locally, which I don't want (hosting on Heroku but temporarily is a good idea so I can see whether the file is being generated correctly). 2) The template does not use the variable Any ideas how I could get this to work? |
Rails Paperclip upload not working AWS Posted: 25 Oct 2016 05:01 AM PDT I'm running an Elasticbeanstalk instance with a Rails5 app running with Postgres. Everything works ok apart from when I try to upload an image via Paperclip. I keep getting the following error:
I'm guessing it's a permissions problem with the public folder. But nervous of messing around with things I won't know how to put right... |
Devise: Add User Details in different table Posted: 25 Oct 2016 06:58 AM PDT I have two models User and Person I want to stick with the default table for the user offered by Devise to include only email and password and add User details in Person Here is my models User Model I also override RegistrationController.rb to look like this and here is the view With the code it didn't work, and it didn't update the people column while registration How Can I get devise to add details in two models using the only one form offered by devise ? To add email and password in Users Table and other details e.g. first_name in People Table |
Updating the values on Many-to-Many relationship table Posted: 25 Oct 2016 07:25 AM PDT I'm facing an issue on the many to many relationship table using ruby on rails. I have two tables and a relationship table(which is a joining table). They are named as follow
My problem is how do i update the values of user roles on the 3rd table. ExampleIf I assign a user_id 34 to admin(role_id = 2) user_id 34 to supervisor(role_id = 3) I should have two entries on Role_User table. Now I would like to update user_id 34 to admin(role_id = 1) How do I do this on rails I have updating the user details with |
raise ActiveRecord::PendingMigrationError if ActiveRecord::Migrator.needs_migration? Posted: 25 Oct 2016 04:58 AM PDT i have run: bin/rake db:migrate RAILS_ENV=development but still nothing happens, i was trying to add community engine to my rails 4.2 app, help anyone? Thanks |
How to temporarily disable Omniauth authentication in Rails? Posted: 25 Oct 2016 06:47 AM PDT I made a Facebook Devise authentication on my Rails 5 site. All the code and settings are standart. But now I would like to temporarily disable it. I want to put a temporary redirect to But I haven't found any controller where I could set such a redirect. Or should I search for some callback? When I click
But no controller is called. How to do the redirect then? I have the controller - but it is called AFTER the www.facebook.com request - not BEFORE as I need. |
Extending an ActiveRecord Polymorphic Association with JOIN statements? Posted: 25 Oct 2016 04:36 AM PDT My tables are set up such that They share a primary key (
The
Thus I've attempted to use Polymorphic Inheritance in ActiveRecord: When I attempt to execute
Notably, there's no
Now I can access the How can I correctly create this JOIN association such that an attempt to load a |
How does Rails View Helper work Posted: 25 Oct 2016 06:02 AM PDT I recently came across a tricky situation related to rails view helpers. The situation is like follows- I am having a controller as So ofcourse related view helpers in folder Now the real problem I am facing is that a few helpers for I was wondering how rails identifies all these helpers as I am noticing that the So does rails consider all helper modules defined in one folder as one? In a view I am using |
How to stop rspec from dropping the test database before tests Posted: 25 Oct 2016 06:49 AM PDT I have two Rails apps that use the same database. One app is managing the database through migrations but the other is just accessing it. For some reason when I run tests with RSpec in the app that is not managing the database it drops the database before running the tests. But because this app does not know how to recreate the database all tests will fail. How can I tell RSpec not to drop the database, just use it as it is? |
Rails 5: Table name not being inferred through class_name Posted: 25 Oct 2016 04:06 AM PDT I have the following rails model: Each I'd like to be able to find connections which point to particular people. For example:
However this gives me the error: I believe this is because its querying I've also tried Any ideas how to achieve this, without having to rename the association? |
Can we create Ruby on Rails API-only Application with ActionCable Live updates? Posted: 25 Oct 2016 06:22 AM PDT How-to create RoR API-only application with ActionCable live updates? Firstly I don't have any experience in Building API's and Front End Technologies, recently I started API's build. I've checked lot of documents, and no use. Kindly, Help me with some good resources or stuff which includes - how we need to subscribe, publish and broadcast using ActionCable in API-only application. |
Nginx + Phusion Passenger + Rails = staging ENV won't be set Posted: 25 Oct 2016 03:51 AM PDT I am having trouble making phusion passenger see that the server is set for staging instead of production. I have changed using sudo nano basically added/changed lines
but still not working, is there anything else i need to do? |
Rails sending a dynamic content and layout to action mailer Posted: 25 Oct 2016 03:31 AM PDT I am creating a dynamic mailer where we can set content as well as css style also. like we create database including subject and mail_body. and the mail body contain the html code including inline css. now how can i pass it to action mailer and fire a mail. Thanks in advance. |
how to submit rails form once with validation check if only all fields are valid Posted: 25 Oct 2016 07:41 AM PDT I have a form in my rails app but it submits multiple times when we click multiple times i want to submit the form once with checking all validations, I tried disabling the button on click but its only desables button with click, not actually send data nor checking validations. please help me, Thanks in advance. |
Questions about Fat-Model, Skinny-Controller practice Posted: 25 Oct 2016 05:41 AM PDT How do you decide that a line of code must be moved from controller to model? I've done some research already about this best practice and here's the best explanations so far, but I hope you guys can expand this well because my newbie brain can't fully comprehend it :)
EDIT: Let's say I want to refactor my controller below from: to Which of these 2 code blocks are correct? or EDIT2: If I want to refactor my controller below from: to my code inside model should be: |
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